多态测试_01

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、

 

posted @ 2016-04-21 09:48  Html5Skill  阅读(183)  评论(0编辑  收藏  举报