一个面向对象的应用

 1  function IElectricalEquipment() {
 2 
 3         }
 4         IElectricalEquipment.prototype = {
 5             poweron: function () {
 6             },
 7             poweroff: function () {
 8             }
 9         };
10 
11         function Fan(){//电风扇
12 
13         }
14         Fan.prototype=new IElectricalEquipment;
15         Fan.prototype.poweron=function(){
16             console.log("Fan'power on")
17         };
18         Fan.prototype.poweroff=function(){
19             console.log("Fan'power off")
20         };
21 
22         function Light(){//电灯
23 
24         }
25         Light.prototype=new IElectricalEquipment;
26         Light.prototype.poweron=function(){
27             console.log("Light'power on")
28         };
29         Light.prototype.poweroff=function(){
30             console.log("Light'power off")
31         };
32 
33 
34         var createSwitch=(function () {
35             function Switch(){
36                 this.equipment=null;
37             }
38             Switch.prototype={
39                 on:function(){
40                     this.equipment.poweron();
41                 },
42                 off:function(){
43                     this.equipment.poweroff();
44                 }
45             };
46             return function(){
47                 return new Switch();
48             }
49         }());
50 
51 
52         var myLight=new Light();
53         var myFan=new Fan();
54         var FanSwitch=createSwitch();
55         FanSwitch.equipment=myFan;
56         FanSwitch.on();
57         FanSwitch.off();
58 
59         FanSwitch.equipment=myLight;
60         FanSwitch.on();
61         FanSwitch.off();

//现在要解决的问题是

  在js中抽象基类是怎么实现的。

转载于:https://www.cnblogs.com/windSamW/p/4938482.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值