zoukankan      html  css  js  c++  java
  • 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();

  • 相关阅读:
    Unity热更新04-XLua调用C#-01-Lua调用C#类
    Unity热更新03-C#调用XLua-010-LuaMgr
    Unity热更新03-C#调用XLua-09-Lua表映射到 XLua的LuaTable中(不建议)
    Unity热更新03-C#调用XLua-07-Lua表映射到C#接口
    Unity热更新03-C#调用XLua-07-Lua表映射到C#类
    C# 禁用控制台应用程序关闭按钮
    只允许输入正整数、负数、 控制小数点不能是第一位,负号必须第一位
    Godot
    GameFramework摘录
    GameFramework摘录
  • 原文地址:https://www.cnblogs.com/koleyang/p/4939877.html
Copyright © 2011-2022 走看看