zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    基于keepalived搭建MySQL的高可用集群
    weblogic启动问题
    wind7下搭建ftp服务器
    数据库连接数使用情况监控
    windows下自动删除n天前的文件
    oracle RAC调整数据文件大小并移动表到指定的表空间
    oracle表空间使用情况查询
    vue的.vue文件是怎么run起来的(vue-loader)
    react router @4 和 vue路由 详解(七)react路由守卫
    react router @4 和 vue路由 详解(六)vue怎么通过路由传参?
  • 原文地址:https://www.cnblogs.com/Again/p/5284834.html
Copyright © 2011-2022 走看看