Skip to content

Instantly share code, notes, and snippets.

@ondrek
Last active August 29, 2015 13:58
Show Gist options
  • Save ondrek/10019637 to your computer and use it in GitHub Desktop.
Save ondrek/10019637 to your computer and use it in GitHub Desktop.
function Test(){
this.element = document.querySelector(".hello");
this.helloWorld();
}
Test.prototype.helloWorld = function(){
var that = this;
this.element addEventListener("click", function(e){ that.whatDidItGet(e) });
// this is helloWorld
this.element.addEventListener("click", that.whatDidItGet);
// this is addEventListener
this.element.addEventListener("click", (function(e){ this.whatDidItGet(e) }).bind(this));
// this is helloWorld
this.element.addEventListener("click", (that.whatDidItGet).bind(this));
// this is helloWorld
};
Test.prototype.whatDidItGet = function(secret){
console.log(secret);
};
new Test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment