看代码
function Parent() {
this.name = "zhangsan";
this.list = [];
}
function Child() {
Parent.call(this);
this.age = 18;
}
Child.prototype.__proto__=Parent.prototype;
Child.prototype.contructor = Child;
上面是继承的常见写法,默认情况下Child.prototype.__proto__应该指向Object.prototype,为了实现child是继承parent的,所以修改原型链
Child.prototype.__proto__=Parent.prototype;
到这我是理解的。
但是为什么修改了__proto__,Child.prototype也变成了Parent呢?__proto__不应该是prototye的一个属性吗?prototype的指向不应该还是Child吗,只是proto指向Parent来实现继承?
修改__proto__不会发生你所说的问题,如果你说的是在控制台打印,前面有写一个Parent,那只是浏览器实现的,对象的类型标识,就是它的构造函数