Skip to content

Instantly share code, notes, and snippets.

@rahulcs
Created March 20, 2014 11:06
Show Gist options
  • Save rahulcs/9661475 to your computer and use it in GitHub Desktop.
Save rahulcs/9661475 to your computer and use it in GitHub Desktop.
Function Invocation and `this`
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