Skip to content

Instantly share code, notes, and snippets.

@dameleon
Created December 10, 2012 07:21
Show Gist options
  • Save dameleon/4249010 to your computer and use it in GitHub Desktop.
Save dameleon/4249010 to your computer and use it in GitHub Desktop.
handleEvent
var eventHandler = {
handleEvent: function(ev) {
switch (ev.type) {
case 'click':
this.click();
break;
case 'touchstart':
this.touch();
break;
}
},
click: function() {
// hogehoge
},
touch: function() {
// hogehoge
}
};
elm.addEventListener('click', eventHandler, false);
elm.addEventListener('touch', eventHandler, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment