天天看点

类的继承

//父类
function Person(){
    this.money=1000  
}
      

  

1.原型链继承

function Sam(){}
Sam.prototype = new Person();
Sam.prototype.address ='中国';
      

2.构造继承

function Sam(){
    Person.call(this)
    this.address='中国'
}
      

3.实例继承

function Sam(){
    var instants = new Person()
    instants.address='中国'    
    return instants
}
      

4.Object.create()方法继承

function Sam (){
   return Object.create(new Person())  
}
      

继续阅读