• design.js


    //模块式开发
    var myNamespace = (function () {

    var myPrivateVar = 0;
    
    var myPrivateMethod = function  (foo) {
    	console.log(foo);
    };
    
    return {
    	myPublicVar : "foo",
    	myPublicFunction : function  (bar) {
    		
    		myPrivateVar++;
    		myPrivateMethod(bar);
    	}
    };
    

    })();

    //原型模式
    var myCar = {
    name: "Ford Escort",
    drive: function () {
    console.log("Weeeee, i'm driving...");
    },
    panic: function () {
    console.log("Wait. How do you stop this thing");
    }
    };

    var yourCar = Object.create(myCar);
    console.log(yourCar.name);

    //命令模式
    var CarManager = {
    requestInfo: function (model, id) {
    return "The information for " + model + "with ID" + id + "is foobar";
    },

    buyVehicle: function  (model, id) {
    	return "You have successfully purchasedItem" + id + ",a " + model;
    },
    
    arrangeViewing: function  (model, id) {
    	return "You have successfully booked a viewing of" + model + " " + id;
    },
    
    execute:function  (name) {
    	return CarManager[name] && CarManager[name].apply(CarManager, [].slice.call(arguments, 1));
    }
    

    }
    CarManager.execute("requestInfo", "Ferrari","12350");

  • 相关阅读:
    jquery 页面滚动到底部事件
    01上古天真论 [音频]
    pyjnius 通过包名获取其他应用程序的名称
    python3 获取当前网络子网ip
    堆排序、快速排序、归并排序总结
    Linux 进程
    链表(转载)
    15-C语言结构体(转载)
    IP地址的分类
    TCP/IP详解
  • 原文地址:https://www.cnblogs.com/lanse-yan/p/3977704.html
Copyright © 2020-2023  润新知