Skip to content

Instantly share code, notes, and snippets.

@matbee-eth
Created June 5, 2012 16:35
Show Gist options
  • Save matbee-eth/2876120 to your computer and use it in GitHub Desktop.
Save matbee-eth/2876120 to your computer and use it in GitHub Desktop.
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