function Gadget(name, color)
{
this.name = name;
this.color = color;
}
Gadget.prototype.rating = 3
var newtoy = new Gadget("webcam", "black")
newtoy.constructor.prototype.constructor.prototype.constructor.prototype
Run Code Online (Sandbox Code Playgroud)
它总是返回rating = 3的对象.
但如果我做以下事情:
newtoy.__proto__.__proto__.__proto__
Run Code Online (Sandbox Code Playgroud)
链条最终返回null.
另外在Internet Explorer中,如果没有__proto__属性,我如何检查null ?
什么网络浏览器使用__proto__?Mozilla说:
请注意,
__proto__除了Mozilla中的JavaScript版本之外,其他版本可能无法使用.
一般来说,扩展node.js或javascript中的原型类.(js newb)
我正在查看expressjs的源代码并看到了这个:
var mixin = require('utils-merge');
....
mixin(app, proto);
mixin(app, EventEmitter.prototype);
Run Code Online (Sandbox Code Playgroud)
Utils-merge看起来像是一个外部模块.上面有什么区别,只做以下事情:
var util = require('util');
....
util.inherit(app, proto);
util.inherit(app, EventEmitter);
Run Code Online (Sandbox Code Playgroud)
这仍然是在尝试扩展属性吗?我很善良 - 迷失在这里:
app.request = { __proto__: req, app: app }; // what is the equivalent for this in util?
app.response = { __proto__: res, app: app };
Run Code Online (Sandbox Code Playgroud)
如果是这样,即使util.inherit使用它仍然有效吗?
app.request = util.inherit(app, req)
Run Code Online (Sandbox Code Playgroud)
或类似的东西?jshint说__proto__是被剥夺了.
另外我也看到了这个?
var res = module.exports = {
__proto__: http.ServerResponse.prototype
};
Run Code Online (Sandbox Code Playgroud)
这可能吗?
var res = module.exports = util.inherits...??
Run Code Online (Sandbox Code Playgroud)