4)Javascript設計模式:Decorator模式

function MacBook() {
    this.cost = function() {
        return 997;
    }
}

var macbook = new MacBook();

function addCost(macbook) {
    var _cost = macbook.cost;
    macbook.cost = function() {
        return _cost() + 100;
    }
}

macbook.cost()
相關文章
相關標籤/搜索