Last active
August 29, 2015 14:21
-
-
Save karenpeng/223d95afe4f34bda3e12 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.x = 9; | |
var module = { | |
x: 81, | |
getX: function() { return this.x; } | |
}; | |
module.getX(); // 81 | |
var getX = module.getX; | |
getX(); // 9, because in this case, "this" refers to the global object | |
// Create a new function with 'this' bound to module | |
var boundGetX = getX.bind(module); | |
boundGetX(); // 81 | |
getX.apply(module); //81 | |
getX.call(module); //81 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment