Skip to content

Instantly share code, notes, and snippets.

@mohnish
Created March 12, 2014 23:40
Show Gist options
  • Select an option

  • Save mohnish/9519023 to your computer and use it in GitHub Desktop.

Select an option

Save mohnish/9519023 to your computer and use it in GitHub Desktop.
PubSub with simple event model in JS
var o = $({});
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
$(document.body).on( 'click', function() {
$.publish('data');
});
$.subscribe( 'data', function() {
console.log('data received');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment