Created
November 28, 2012 15:53
-
-
Save ivillamil/4162131 to your computer and use it in GitHub Desktop.
PubSub [observer pattern with jQuery]
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
/* | |
| Include this snippet before your scripts in order to get access to the pubSub pattern | |
| USAGE: | |
| $.publish('myApp:customEvent'); | |
| $.suscribe('myApp:customEvent', yourCallbackFunction); | |
**/ | |
(function( $ ) { | |
var o = $( {} ); | |
$.each({ | |
trigger: 'publish', | |
on: 'suscribe', | |
off: 'unsuscribe' | |
},function(key, val){ | |
jQuery[val] = function() { | |
o[key].apply(o, arguments ); | |
} | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment