Created
March 20, 2014 11:06
-
-
Save rahulcs/9661475 to your computer and use it in GitHub Desktop.
Function Invocation and `this`
This file contains hidden or 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
1. When a function is invoked by '()' , `this` is set to the window global object. | |
2. Invocation as a method of an object will set `this` to the object itself. | |
3. Invocation as a contstructor referenced with the 'new' keyword, the object is passed as 'this' to the constructor and any absence of an explicit return value with always return the new object created as the constructor. | |
4. Invocation via call/apply passes an object as function parameter & that object will be set to `this`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment