- 微信扫码关注公众号 :前端前端大前端,追求更精致的阅读体验 ,一起来学习啊
- 关注后发送关键资料,免费获取一整套前端系统学习资料和老男孩python系列课程
function Person(name) {
this.name = name;
}
Person.prototype.say=function(){
console.log(`My name is ${this.name}`)
}
function Student(name) {
Person.call(this, name)
}
// Object.create方法创建一个新对象,使用现有的对象来提供新创建的对象的__proto__
Student.prototype=Object.create(Person.prototype);
// 修正构造函数指向 Person=>Student
Student.prototype.constructor=Student;
var stu=new Student("tom");
stu.say()//My name is tom