JS中继承实现的几种方式,
function Person(){
this.name='小明'
this.getName=function () {
console.log(this.name)
}
}
Person.prototype.get = () => {
console.log('原型链上的方法')
} function Student(){}
Student.prototype = new Person(); function Student(){
Person.call(this);
} 3.组合继承 function Student(){
Person.call(this);
}
Student.prototype = new Person(); 4.寄生组合继承 function Student(){
Person.call(this);
}
const Fn = function () {};
Fn.prototype = Person.prototype;
Student.prototype = new Fn(); 5.ES6 extends class Student extends Person{};