Skip to content

Instantly share code, notes, and snippets.

@christopherhill
Created October 19, 2013 04:59
Show Gist options
  • Select an option

  • Save christopherhill/7051812 to your computer and use it in GitHub Desktop.

Select an option

Save christopherhill/7051812 to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment