Created
December 6, 2011 16:08
-
-
Save yonestra/1438731 to your computer and use it in GitHub Desktop.
useage of nested this (JS)
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
<input type="button" value="A" id="buttonA" > | |
<input type="button" value="B" id="buttonB" > | |
<script> | |
var objectA = new function () { | |
this.alertMessage = "Hello world!"; | |
this.ClickHandler = function() { | |
alert(this.alertMessage ); | |
} | |
}; | |
document.getElementById("buttonA").onclick = objectA.ClickHandler //undefined | |
var objectB = new function () { | |
var self = this; | |
this.alertMessage = "Hello world!"; | |
this.ClickHandler = function() { | |
alert(self.alertMessage); | |
} | |
}; | |
document.getElementById("buttonB").onclick = objectB.ClickHandler //Hello world! | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment