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()

你可能感兴趣的:(4)Javascript设计模式:Decorator模式)