Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@samzhao
Created March 7, 2012 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samzhao/1991809 to your computer and use it in GitHub Desktop.
Save samzhao/1991809 to your computer and use it in GitHub Desktop.
Javascript: Clever pubsub
// Works in modern browsers + IE9, but Modernizr has to 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