function Son(name, gender, hobby) {
Father.call(this, name, gender);
this.hobby = hobby;
}
function Father(name, gender) {
this.name = name;
this.gender = gender;
}
Father.prototype.walk = () => console.log("I can walk");
function extends2_(son, father) {
const obj = Object.create(father.prototype, {
constructor: {
value: son
}
});
son.prototype = obj;
}
extends2_(Son, Father);
const son = new Son("zhangsan", "male", "basketball");
console.log("son", son);
经测试可用
登录后可查看更多问答,登录/注册