Created
March 28, 2014 15:35
-
-
Save user24/9835573 to your computer and use it in GitHub Desktop.
This file contains 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 SomeBuggyInstantiatedObject() { | |
this.name = "bob"; | |
someElement.onclick = function() { | |
alert(this.name); // undefined, because this context is the click event | |
} | |
} | |
function SomeSuperCoolInstantiatedObject() { | |
var that = this; | |
this.name = "bob"; | |
someElement.onclick = function() { | |
alert(that.name); // bob, because that is sealed in scope when the function was declared | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment