Skip to content

Instantly share code, notes, and snippets.

@ksafranski
Created December 15, 2012 20:40
Show Gist options
  • Select an option

  • Save ksafranski/4298991 to your computer and use it in GitHub Desktop.

Select an option

Save ksafranski/4298991 to your computer and use it in GitHub Desktop.
Really small jQuery pub/sub script
// See example at http://jsfiddle.net/fluidbyte/AhBKq/
var broadcast = {
speak: function (name, message) {
$(document).trigger(name, message);
},
listen: function (name, callback) {
$(document).bind(name, function (e, message) {
if (callback && typeof (callback) === "function") {
callback(message);
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment