• js原生之一个面向对象的应用


    function IElectricalEquipment() {

            }
            IElectricalEquipment.prototype = {
                poweron: function () {
                },
                poweroff: function () {
                }
            };

            function Fan(){//电风扇

            }
            Fan.prototype=new IElectricalEquipment;
            Fan.prototype.poweron=function(){
                console.log("Fan'power on")
            };
            Fan.prototype.poweroff=function(){
                console.log("Fan'power off")
            };

            function Light(){//电灯

            }
            Light.prototype=new IElectricalEquipment;
            Light.prototype.poweron=function(){
                console.log("Light'power on")
            };
            Light.prototype.poweroff=function(){
                console.log("Light'power off")
            };


            var createSwitch=(function () {
                function Switch(){
                    this.equipment=null;
                }
                Switch.prototype={
                    on:function(){
                        this.equipment.poweron();
                    },
                    off:function(){
                        this.equipment.poweroff();
                    }
                };
                return function(){
                    return new Switch();
                }
            }());


            var myLight=new Light();
            var myFan=new Fan();
            var FanSwitch=createSwitch();
            FanSwitch.equipment=myFan;
            FanSwitch.on();
            FanSwitch.off();

            FanSwitch.equipment=myLight;
            FanSwitch.on();
            FanSwitch.off();

  • 相关阅读:
    window.close关闭当前页面
    select设置innerHMTL
    google禁止更新服务
    git 建立仓库步骤
    git 第一次上传报错 rejected error: failed to push some refs to
    selenium WebDriverWait 重写子类,赋值真实异常message
    vmware centos 设置静态ip
    xdist ModuleNotFoundError: No module named 'xxxx',xxx为自定义的模块
    python eval 内置函数用法
    windows使用python脚本实现ssh-copy-id免密钥ssh登录linux
  • 原文地址:https://www.cnblogs.com/koleyang/p/4939877.html
Copyright © 2020-2023  润新知