Created
December 25, 2017 19:46
-
-
Save jacky810124/bc63a044d3a0371892a833a1de2c8fd7 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
// 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