christopherhill
10/19/2013 - 4:59 AM

Value Watcher class for JS

Value Watcher class for JS

function ValueWatcher(value, callback, prequel) {
    var that = this;
    this.value = value;
    this.onBeforeSet = prequel || function(){};
    this.onAfterSet = callback || function(){};
    this.setValue = function(newVal) {
        that.onBeforeSet(that.value, newVal);
        that.value = newVal;
        that.onAfterSet(newVal);
    }
    this.getValue = function() {
        return that.value;
    }
}