Skip to content

Instantly share code, notes, and snippets.

@fuzzyfox
Last active December 19, 2015 15:58
Show Gist options
  • Save fuzzyfox/5979674 to your computer and use it in GitHub Desktop.
Save fuzzyfox/5979674 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.
// Hat tip Paul Irish
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