Skip to content

Instantly share code, notes, and snippets.

@dokipen
Created April 26, 2010 16:16
Show Gist options
  • Save dokipen/379538 to your computer and use it in GitHub Desktop.
Save dokipen/379538 to your computer and use it in GitHub Desktop.
Generic pub-sub in Prototype
PubSub = {
initPubSub: function() {
this._dummy = new Element('span');
},
fire: function(event, memo) {
this._dummy.fire(event, memo);
},
observe: function(event, handler) {
this._dummy.observe(event, handler);
}
}
var MyClass = Class.create(PubSub, {
initialize: function() {
this.initPubSub();
}
});
var myInstance = new MyClass();
myInstance.observe('myclass:custom', function(event) {
console.log(event);
});
myInstance.fire('myclass:custom', {a: 'memo'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment