1 <script type="text/javascript">
 2  function Animal () {
 3      this.species="Animal";
 4  }
 5 function Cat(name,color){
 6     this.name=name;
 7     this.color=color;
 8 }
 9 //Apply 将父类对象的构造函数赋值到子类上,Animal.apply(this,arguments);
10  function Cat(name,color){
11      this.name=name;
12      this.color=color;
13      Animal.apply(this,arguments);
14  }
15  var cat1=new Cat("大毛","黄色");
16  alert(cat1.species);
17 
18 //Prototype 子对象原型prototype赋值父类对象,并将子类对象原型的构造函数赋值为子类
19 Cat.prototype = new Animal();
20 Cat.prototype.constructor=Cat;
21 var cat1=new Cat("大毛","黄色");
22 alert(cat1.species);
23 </script>

 

相关文章:

  • 2021-09-05
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-05-10
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2021-05-09
  • 2021-06-05
  • 2021-08-01
  • 2022-12-23
相关资源
相似解决方案