Created
October 29, 2011 17:22
-
-
Save whytheplatypus/1324810 to your computer and use it in GitHub Desktop.
Javascript event callback work around
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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