Skip to content

Instantly share code, notes, and snippets.

@biomathcode
Last active June 30, 2022 17:21
Show Gist options
  • Save biomathcode/28ec3d45477228d5390f993753a510c2 to your computer and use it in GitHub Desktop.
Save biomathcode/28ec3d45477228d5390f993753a510c2 to your computer and use it in GitHub Desktop.
function observable(v){
this.value = v;
this.valueChangedCallback = null;
this.setValue = function(v){
if(this.value != v){
this.value = v;
this.raiseChangedEvent(v);
}
};
this.getValue = function(){
return this.value;
};
this.onChange = function(callback){
this.valueChangedCallback = callback;
};
this.raiseChangedEvent = function(v){
if(this.valueChangedCallback){
this.valueChangedCallback(v);
}
};
}
var obs = new observable(123);
obs.onChange(function(v){
alert("value changed to: " + v);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment