利用原型链实现继承
function Parent() {
this.sayAge = function () {
console.log(this.age);
};
}
function Child(firstname) {
this.fname = firstname;
this.age = 40;
this.saySomeThing = function () {
console.log(this.fname);
this.sayAge();
};
}
Child.prototype = new Parent();
let child = new Child("zhang");
child.saySomeThing(); // zhang 40
console.log(child instanceof Parent); // true最后更新于