/** * 混合模式 = 原型模式 + 构造函数模式 */ 
function Animal(name, color){ 
    this.name = name; 
    this.color = color; 
    console.log( this.name + this.color) 
} 
Animal.prototype.getInfo = function(){ 
    console.log('名称:'+ this.name); 
} 
function largeCat(name, color){ 
    Animal.call(null, name, color); 
    this.color = color; 
} 
largeCat.prototype = create(Animal.prototype); 
function create (parentObj){ 
    function F(){} 
    F.prototype = parentObj; 
    return new F(); 
}; 
largeCat.prototype.getColor = function(){ return this.color; } 
var cat = new largeCat("Persian", "白色"); console.log( cat )

  

相关文章:

  • 2021-08-23
  • 2021-07-29
  • 2021-11-01
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-10-02
  • 2022-01-04
猜你喜欢
  • 2021-08-25
  • 2021-11-22
  • 2021-05-25
  • 2021-10-06
  • 2022-01-27
  • 2021-12-07
  • 2021-12-22
相关资源
相似解决方案