• javascript 老王开车去东北


    [Decode error - output not utf-8]
    魔女
    飞
    奔驰
    去
    华南
    [Finished in 1.1s]

    需要变化的对象进行隔离。正是编程的乐趣之处

    /**
     * by JackChen 2016-3-15 9.21.57
     * 基于马士兵老师的设计模式视频
     * 入门: 老王开车去东北 封装
     */
    //////////////////////////////////////////////////////////////////////
    /// 封装
    
    //////////////////////////////////////////////////////
    var Driver = function(name) {
        var self = this;
    
        self.name = name;
    };
    Driver.prototype = {};
    Driver.prototype.constructor = Driver;
    
    Driver.prototype.Name = function() {
        var self = this;
        console.log(self.name);
    };
    
    Driver.prototype.Do = function() {
        var self = this;
        console.log('开');
    };
    
    //////////////////////////////////////////////////////
    var Witch = function(name) {
        var self = this;
    
        self.name = name;
    };
    Witch.prototype = new Driver();
    Witch.prototype.constructor = Witch;
    
    Witch.prototype.Name = function() {
        var self = this;
        console.log(self.name);
    };
    
    Witch.prototype.Do = function() {
        var self = this;
        console.log('飞');
    };
    
    
    
    
    
    
    
    //////////////////////////////////////////////////////
    var Car = function(name) {
        var self = this;
    
        self.name = name;    
    };
    Car.prototype = {};
    Car.prototype.constructor = Car;
    
    //循环调用自己的子元素
    Car.prototype.Name = function() {
        var self = this;
        console.log(self.name);
    };
    
    
    
    
    
    
    
    
    
    
    
    //////////////////////////////////////////////////////
    var Place = function(name) {
        var self = this;
    
        self.name = name;    
    };
    Place.prototype = {};
    Place.prototype.constructor = Place;
    
    //循环调用自己的子元素
    Place.prototype.Name = function() {
        var self = this;
        console.log(self.name);
    };
    
    
    
    
    
    
    
    
    
    
    
    //////////////////////////////////////////////////////
    var Travel = function(driver, tool , place) {
        var self = this;
        self.driver = driver;
        self.tool = tool;
        self.place = place;
    };
    Travel.prototype = {};
    Travel.prototype.constructor = Travel;
    
    //循环调用自己的子元素
    Travel.prototype.travel = function() {
        var self = this;
        self.driver.Name();
        self.driver.Do();
        self.tool.Name();
        console.log('去');
        self.place.Name();
    };
    
    
    
    
    
    
    
    
    
    
    
    
    
    /////////////////////////////////////////////////////////////////////
    /// 测试
    
    // console.log('老王开车去东北');
    
    var driver = new Witch("魔女");
    var car = new Car("奔驰");
    var place = new Place("华南");
    
    var travel = new Travel(driver, car, place);
    travel.travel();
    View Code
  • 相关阅读:
    HAProxy、Keepalived 在 Ocatvia 的应用实现与分析
    Octavia 的 HTTPS 与自建、签发 CA 证书
    Octavia 创建 loadbalancer 的实现与分析
    OpenStack Rally 质量评估与自动化测试利器
    自建 CA 中心并签发 CA 证书
    Failed building wheel for netifaces
    通过 vSphere WS API 获取 vCenter Datastore Provisioned Space 置备空间
    OpenStack Placement Project
    我们建了一个 Golang 硬核技术交流群(内含视频福利)
    没有图形界面的软件有什么用?
  • 原文地址:https://www.cnblogs.com/Again/p/5284834.html
Copyright © 2020-2023  润新知