Skip to content

Instantly share code, notes, and snippets.

@zaus
Forked from cowboy/HEY-YOU.md
Last active December 12, 2015 10:08
Show Gist options
  • Save zaus/4756518 to your computer and use it in GitHub Desktop.
Save zaus/4756518 to your computer and use it in GitHub Desktop.
/* jQuery Tinier Pub/Sub - v0.9 - 2013-02-11
* original by http://benalman.com/ 10/27/2011
* Original Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
// "topic" holder
var o = $({}); // use $('<b>') with Zepto, as it doesn't like {} ?
// attach each alias method
$.each(['on','off','trigger'], function(i,method) {
$[method] = function(topic, callbackOrArgs) {
o[method].apply(o, arguments);
}
});
}(jQuery));

Fork and "simplification" of jQuery Tiny Pubsub. Two alternate versions -- one with my preferred "on/off/go" syntax, the other with jQuery-standard "on/off/trigger".

Update: do is a reserved keyword, and even though it's a property it still chokes <IE9.

See testing at jsfiddle.

See original Tiny Pubsub by Ben Alman: gist repo.

/* jQuery Tinier Pub/Sub - v0.9b - @see https://gist.github.com/zaus/4756518 */
(function(e){var t=e({});e.each({on:0,off:0,"go":"trigger"},function(n,r){e[n]=function(e,i){t[r||n].apply(t,arguments)}})})(jQuery)
/* jQuery Tinier Pub/Sub - v0.9b - "on/off/do version" - 2013-02-11
* original by http://benalman.com/ 10/27/2011
* Original Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
// "topic" holder
var o = $({}); // use $('<b>') with Zepto, as it doesn't like {} ?
// attach each alias method
$.each({on:0,off:0,go:'trigger'}, function(alias,method) {
$[alias] = function(topic, callbackOrArgs) {
o[method || alias].apply(o, arguments);
}
});
}(jQuery));
@zaus
Copy link
Author

zaus commented Feb 19, 2013

crap. "do" throws an error in <IE9 even when a property -- http://jonathonhill.net/2009-11-24/javascript-reserved-words-trigger-expected-identifier-error-on-ie/. I knew there was a reason the "pros" stuck with trigger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment