Skip to content

Instantly share code, notes, and snippets.

@5509
Created April 4, 2011 09:42
Show Gist options
  • Save 5509/901376 to your computer and use it in GitHub Desktop.
Save 5509/901376 to your computer and use it in GitHub Desktop.
汎用addEventListener(IE8以下を除く)
/*
* Bind events
* bind(obj, listener, func)
* or
* bind(obj, {
* listener : func,
* listener2 : func2,
* // and more
* })
*/
function bind() {
var i, _a = arguments;
if ( typeof _a[1] === "object" ) {
for ( i in _a[1] ) {
bindFunc(i, _a[1][i]);
}
} else {
bindFunc(_a[1], _a[2]);
}
function bindFunc(listener, func) {
var i;
listener = listener.split(" ");
for ( i = 0, l = listener.length; i < l; i++ ) {
_a[0].addEventListener(listener[i], func, false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment