JavaScript / Node.js:为什么原型.__ proto__ =原型,而不是新的
我正在研究node.js的Express框架,所有的inheritance都是通过:
Collection.prototype.__proto__ = Array.prototype;
这不等于:
Collection.prototype = new Array;
另一个:
var app = HTTPSServer.prototype; function HTTPSServer(options, middleware){ connect.HTTPSServer.call(this, options, []); this.init(middleware); }; app.__proto__ = connect.HTTPSServer.prototype;
那些批评有什么好处吗?
提前致谢!
范例来自:
https://github.com/visionmedia/express/blob/master/lib/router/collection.js
https://github.com/visionmedia/express/blob/master/lib/https.js
new Array
调用一个构造函数。 设置__proto__
不。 这是唯一的区别。
我认为作者太懒惰不想使用Object.create
Collection.prototype = new Array;
每个集合将共享相同的Array实例。
我不确定这是否适用于__proto__
?