Last active
August 29, 2015 14:14
-
-
Save appkr/b305d00debb79d404f75 to your computer and use it in GitHub Desktop.
JavaScript This Keyword// source http://jsbin.com/gepage
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" keyword | |
var makeRequest = function(url, callback) { | |
var data = 10; // Ajax | |
callback(data); | |
}; | |
var obj = { | |
someValue : 20, | |
loadData: function(data) { | |
var sum = this.someValue + data; | |
alert(sum); | |
}, | |
prepareRequest: function() { | |
var url = "http://numberservice.com"; | |
// "this" means obj. | |
makeRequest(url, this.loadData.bind(this)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment