Skip to content

Instantly share code, notes, and snippets.

@whytheplatypus
Created October 29, 2011 17:22
Show Gist options
  • Save whytheplatypus/1324810 to your computer and use it in GitHub Desktop.
Save whytheplatypus/1324810 to your computer and use it in GitHub Desktop.
Javascript event callback work around
function MyObject(){
this.button = document.getElementById("myButton");
var workAroundTheClosure = this;
this.button.addEventListener('click', function(){
workAroundTheClosure.buttionClick();
},
false);
}
MyObject.prototype.buttonClick = function(){
console.log("it works!");
//at least in chrome I've also been able to get at the event object...cool!
console.log(event.target.id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment