Skip to content

Instantly share code, notes, and snippets.

@zwang008
Forked from yakcode/gist:4187013
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save zwang008/547228598bf4229b3a77 to your computer and use it in GitHub Desktop.

Select an option

Save zwang008/547228598bf4229b3a77 to your computer and use it in GitHub Desktop.
JavaScript: Sexy PubSub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Uses Javascript's new bind function
//Hat tip Paul Irish 'and tuts'
var o = $( {} );
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment