Created
August 22, 2017 18:08
-
-
Save kageurufu/a6ac9aa49bc6dddfc5161ef21a9bfa22 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
var Observable = (function(){ | |
function O(initial) { | |
this._value = initial; | |
this._callbacks = []; | |
return this; | |
} | |
O.prototype = { | |
get: function() { return this.value; }, | |
set: function(value) { this._value = value; this.triggerChange(); }, | |
listen: function(handler) { this._callbacks.push(handler); }, | |
triggerChange: function() { | |
for (var i = this._callbacks.length - 1; i >= 0; i--) { | |
this._callbacks[i](this._value); | |
} | |
} | |
} | |
return O; | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hmmmmm I dunno bro