Skip to content

Instantly share code, notes, and snippets.

@rhysbrettbowen
Created September 10, 2012 17:29
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 rhysbrettbowen/3692331 to your computer and use it in GitHub Desktop.
Save rhysbrettbowen/3692331 to your computer and use it in GitHub Desktop.
Bound event object
var bound = goog.events.listen(src, type, function);
// should dispatch event of type on provided targets (or else the src)
bound.fire([optional_targets]);
// will call unbind the event
bound.unlisten();
// can do things like:
var bound = goog.events.listen(src, type, function).fire();
// so you can run a function
// bound object should have fire, unlisted and the id available and look something like:
{
type: [types],
id: id_returned_by_goog_events_listen,
src: the_source,
fn: the function,
capture: true_false,
handler: context_for_fn,
fire: function(opt_targets) {
goog.array.forEach(types, function(type) {
var target = this.src;
if (opt_targets)
target = opt_targets;
if (!goog.isArray(opt_targets))
target = [opt_targets];
goog.array.forEach(target, function(src) {
src.dispatchEvent(type);
});
};
},
unlisten: function() {
goog.events.unlistenByKey(this.id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment