Created
June 12, 2013 12:59
-
-
Save johnmaxwell/5765023 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
// this won't work because "this" doesn't map to this object | |
// when the click handler fires. | |
{ | |
setupHandler: function () { | |
$('button').click(function () {this.handleClicks}); | |
}, | |
handleClicks: function () { | |
alert("I got clicked"); | |
} | |
} | |
// So you have to assign "this" to "that" so that it can | |
// be bound the click handlers closure. | |
{ | |
setupHandler: function () { | |
var that = this; | |
$('button').click(function () {that.handleClicks}); | |
}, | |
handleClicks: function () { | |
alert("I got clicked"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment