View difference between Paste ID: Dst4jLfy and 3yFtjffu
SHOW: | | - or go back to the newest paste.
1
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
2
// Hat tip Paul Irish
3
4
var o = $( {} );
5
$.subscribe = o.on.bind(o);
6
$.unsubscribe = o.off.bind(o);
7
$.publish = o.trigger.bind(o);
8
9
// Usage
10
$(document.body).on( 'click', function() {
11
   // ...yadada
12
   $.publish( 'clicketyClack' ); // Think Rocky Balboa yelling out the window: "Hey yo!"
13
});
14
15
// And some dude listening patiently for Rocky's voice.
16
$.subscribe( 'clicketyClack', function() {
17
	console.log("You can't win, Rock");
18
});