Created
June 5, 2012 16:35
-
-
Save matbee-eth/2876120 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 (data) { | |
var _data = data; | |
var _callbacks = []; | |
var self = this; | |
this.subscribe = function (callback) { | |
_callbacks.push(callback); | |
}; | |
this.get = function () { | |
return _data; | |
}; | |
this.set = function (newValue) { | |
_data = newValue; | |
for (var i = 0; i < _callbacks.length; i++) { | |
_callbacks[i](newValue); | |
}; | |
}; | |
this.watch = function (callback) { | |
_callbacks.push(callback); | |
}; | |
return self; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment