1 var Animal = function() {};
 2 
 3 Animal.prototype.breath = function() {
 4     console.log('breath');
 5 };
 6 
 7 var Dog = function() {};
 8 
 9 //Dog继承了Animal
10 Dog.prototype = new Animal;
11 
12 Dog.prototype.wag = function() {
13     console.log('wag tail');
14 };
15 
16 var dog = new Dog;
17 dog.wag();
18 dog.breath(); //继承的属性

 

日志: wag tail
日志: breath

相关文章:

  • 2021-05-01
  • 2022-12-23
  • 2021-12-02
  • 2021-12-25
  • 2021-12-27
  • 2022-01-18
猜你喜欢
  • 2021-05-20
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案