Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
- // Hat tip Paul Irish
- var o = $( {} );
- $.subscribe = o.on.bind(o);
- $.unsubscribe = o.off.bind(o);
- $.publish = o.trigger.bind(o);
- // Usage
- $(document.body).on( 'click', function() {
- // ...yadada
- $.publish( 'clicketyClack' ); // Think Rocky Balboa yelling out the window: "Hey yo!"
- });
- // And some dude listening patiently for Rocky's voice.
- $.subscribe( 'clicketyClack', function() {
- console.log("You can't win, Rock");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement