Skip to content

Instantly share code, notes, and snippets.

@satoshun
Created March 24, 2013 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satoshun/5231559 to your computer and use it in GitHub Desktop.
Save satoshun/5231559 to your computer and use it in GitHub Desktop.
test observer
describe('design pattern', function () {
var testData = null;
it('observer', function(){
var Observer = function(){
this.subscribers = [];
};
Observer.prototype = {
publish: function(data){
var i = 0,
len = this.subscribers.length;
for(; i<len; i++){
this.subscribers[i](data);
}
},
subscribe: function(callback){
this.subscribers.push(callback);
}
};
var observer = new Observer();
var registry = function(data){
testData = data;
};
observer.subscribe(registry);
observer.publish("end");
expect(testData).not.toBe(null);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment