js实现继承的几种常见方法
1. 实例继承:
function Person(){ this.name="liming"; } var people1=new Person() console.log(people1.name) //liming
2. 原型链继承
function Person(){ this.name="Bob"; } function Student(){ } Student.prototype=new Person();//将Person实例赋值给Student的原型对象 var one=new Student(); console.log(one.name) //Bob
3.构造函数继承
function Person() { this.name="Bob"; } function Child(){ Person.call(this) console.log(this.name) } Child()