Skip to content

Instantly share code, notes, and snippets.

@hrkd
Created May 16, 2013 10:21
Show Gist options
  • Select an option

  • Save hrkd/5590782 to your computer and use it in GitHub Desktop.

Select an option

Save hrkd/5590782 to your computer and use it in GitHub Desktop.
イベントの登録・解除をjQueryぽく。
Object.prototype.addEvent=function(type,func){
var tmpFnc = func;
eval("var "+type.split(".")[1]+"=tmpFnc");
this.addEventListener(type.split(".")[0], eval(type.split(".")[1]), false);
};
Object.prototype.removeEvent=function(type){
this.removeEventListener(type.split(".")[0], eval("this."+type.split(".")[1]), false);
};
//target.addEvent("click.name",function(){});
//target.removeEvent("click.name");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment