Skip to content

Instantly share code, notes, and snippets.

@yonestra
Created December 6, 2011 16:08
Show Gist options
  • Save yonestra/1438731 to your computer and use it in GitHub Desktop.
Save yonestra/1438731 to your computer and use it in GitHub Desktop.
useage of nested this (JS)
<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