js設計模式探索

/**
 * Created by 張猛 on 2017/6/29.
 */

/*模板方法*/
var Beverage = function (param) {
    this.param = param
    // console.log(this.param);
    this.brew()
};
  Beverage.prototype.brew = function () {
    console.log(this.param)
  };
  Beverage.prototype.pourInCup =function () {

  };
  Beverage.prototype.addCondiment =function () {

  };

  Beverage.prototype.init =function () {
      this.brew();
      this.pourInCup();
      this.addCondiment();

  };
  // Beverage();
  var Coffee =function () {
      
  };
  Coffee.prototype = new Beverage();
  Coffee.prototype.brew = function () {
      console.log('用沸水衝')
  };
  Coffee.prototype.pourInCup = function () {
      console.log('把咖啡倒進杯子')
  };
  Coffee.prototype.addCondiment = function () {
      console.log('加入牛奶')
  };

  var coffee = new Coffee();
  coffee.init();
相關文章
相關標籤/搜索