Last active
June 30, 2022 17:21
-
-
Save biomathcode/28ec3d45477228d5390f993753a510c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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