Skip to content

Instantly share code, notes, and snippets.

@crongro
Created January 29, 2015 04:45
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 crongro/62a7b2d64895268dbd4d to your computer and use it in GitHub Desktop.
Save crongro/62a7b2d64895268dbd4d to your computer and use it in GitHub Desktop.
attach Events using 'handlEvent'
function TA() {
this.ele = document.querySelector("#message");
this._attachEvents();
}
TA.prototype = {
_handlers : {
click : '_clickHandler',
mousedown : '_mousedownHandler', /* test */
touchstart: '_touchHandler',/* test */
keyup : '_keyHandler',/* test */
},
_attachEvents : function() {
this.ele.addEventListener('click', this, false);
},
handleEvent : function(e) {
console.log("handleEvent called : ", e.type);
var fpHandler = this[this._handlers[e.type]];
fpHandler.call(this, e);
},
_clickHandler : function(e) {
console.log("clicked!!!", e.type);
}
};
var ta = new TA();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment