下面的代码片段为同一构造函数(Child)的两个实例提供了不同的输出。第一个对象(instance1)没有原型,第二个(instance2)是原型,为什么?
parent=function(){
parent.prototype.method1= function() {}
parent.prototype.property = true;
};
child=function() {
parent.call(this);
child.prototype = new parent();
};
(function(){
var instance1 = new child();
console.log( instance1 ); // Empty Object
var instance2 = new child();
console.log( instance2 ); // Object is not empty
}());
输出: