function Parent() {
this.name = 'parent';
this.colors = ['black', 'yellow', 'red']
}
function Child() {
Parent.call(this);
this.type = 'child';
}
Parent.prototype.age = 12;
Parent.prototype.say = function(){
console.log('hello');
}
var q1 = new Child();
console.log(q1.name); // parent
console.log(q1.colors);// [ 'black', 'yellow', 'red' ]
console.log(q1); //Child {name: "parent", colors: Array(3), type: "child"}
console.log(q1.age); // undefined
console.log(q1.say()); // 报错 TypeError: q1.say is not a function
ES5 构造函数继承
最新推荐文章于 2024-07-12 17:53:13 发布