function Parent() {
this.name = 'kevin';
}
Parent.prototype.getName = function () {
console.log(this.name);
}
function Child() {
// 这里为什么不能这样写
// Child.prototype = new Parent();
}
Child.prototype = new Parent();
var child1 = new Child();
var child1 = new Child()
会先创建一个对象,然后把Child.prototype
赋值给新对象.__proto__
,此时Child.prototype
还不是new Parent
,最后是将构造函数的作用域赋给新对象运行构造函数,所以在Child中设置Child.prototype
晚了