Created
March 24, 2013 11:41
-
-
Save satoshun/5231559 to your computer and use it in GitHub Desktop.
test observer
This file contains hidden or 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
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