码迷,mamicode.com
首页 > 其他好文 > 详细

多态测试_01

时间:2016-04-21 10:10:52      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

1、测试代码:

 1 <html>
 2 
 3 <script type="text/javascript">
 4     window.onload = function()
 5     {
 6         var b = new TbaseB(1);
 7         b.SayHi();
 8     };
 9 
10     function TbaseA(_i)
11     {
12     }
13 
14     TbaseA.prototype = 
15     {
16         SayHi : function()
17         {
18             console.log("TbaseA.SayHi()");
19             console.log("this.Fb(TbaseA) : "+this.Fb);
20         },
21     };
22 
23     function TbaseB(_i)
24     {
25         this.baseA = TbaseA;
26         this.baseA(_i);
27         delete this.baseA;
28 
29         this.Fb = 1;
30     }
31 
32     TbaseB.prototype = 
33     {
34         SayHi : function()
35         {
36             TbaseA.prototype.SayHi.call(this);
37             console.log("TbaseB.SayHi()");
38             console.log("this.Fb(TbaseB) : "+this.Fb);
39         },
40     };
41 
42 
43     
44 </script>
45 
46 </html>

 

chrome(版本 49.0.2623.112 m) 控制台输出信息为:

1 zzz.html:18 TbaseA.SayHi()
2 zzz.html:19 this.Fb(TbaseA) : 1
3 zzz.html:37 TbaseB.SayHi()
4 zzz.html:38 this.Fb(TbaseB) : 1

 

2、

 

多态测试_01

标签:

原文地址:http://www.cnblogs.com/h5skill/p/5415764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!