冒充继承

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 2 <html>
 3     <head>
 4         <title>11-冒充继承</title>
 5         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 6         <meta name="description" content="" />
 7         <meta name="keywords" content="" />
 8 
 9         <script type="text/javascript">
10         //冒充继承
11         function Cat(){
12             this.weapon = "伶牙俐齿";
13             this.climb = function(){
14                 console.log('在爬树');
15             }
16         }
17 
18         function Tiger(){
19             //如果在这个地方把Cat构造函数的代码给执行一次
20             //这样Tiger的对象也会拥有Cat对应的成员
21             //window.Cat();
22             Cat.call(this);//this就是north的指引,这样Cat函数内部的this就是north
23             this.color = "yellow and black";
24             this.weight = 200;
25         }
26 
27         var north = new Tiger;
28         console.log(north);
29         //该方式没有复制继承灵活,每实例化的对象都会用户全部的成员。
30         </script>
31 
32         <style type="text/css">
33         </style>
34     </head>
35 
36 
37     <body>
38     </body>
39 </html>
11-冒充继承

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案