Skip to content

Instantly share code, notes, and snippets.

@karenpeng
Last active August 29, 2015 14:21
Show Gist options
  • Save karenpeng/223d95afe4f34bda3e12 to your computer and use it in GitHub Desktop.
Save karenpeng/223d95afe4f34bda3e12 to your computer and use it in GitHub Desktop.
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