js實現組合繼承(es5)

轉自神三元的博客,這段代碼真的很美

組合繼承(簡直完美)

function Parent5 () {
    this.name = 'parent5';
    this.play = [1, 2, 3];
  }
  function Child5() {
    Parent5.call(this); //使用call改變作用域
    this.type = 'child5';
  }
  Child5.prototype = Object.create(Parent5.prototype); //集成原型上的屬性和方法
  Child5.prototype.constructor = Child5;  //集成直接對象上的屬性和方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章