Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacky810124/bc63a044d3a0371892a833a1de2c8fd7 to your computer and use it in GitHub Desktop.
Save jacky810124/bc63a044d3a0371892a833a1de2c8fd7 to your computer and use it in GitHub Desktop.
// An object can be passed as the first argument to call or apply and this will be bound to it.
var obj = {a: 'Custom'};
// This property is set on the global object
var a = 'Global';
function whatsThis(arg) {
return this.a; // The value of this is dependent on how the function is called
}
whatsThis(); // 'Global'
whatsThis.call(obj); // 'Custom'
whatsThis.apply(obj); // 'Custom'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment