Master JavaScript ‘this’ in 30 Mins

Do you know, there are four ways to calculate the value of ‘this’ inside a JavaScript function? 

Some pointers about ‘this’ 

  • Every function has it’s own ‘this’ 
  • An arrow function does not have it’s own ‘this’
  • The value of ‘this’ depends on, how that function is called
  • The value of ‘this does not depend on how the function is created.

There are four ways a function can be called which are also known as Invocation Patterns. 

  1. Function Invocation Pattern – global object 
  2. Constructor Invocation Pattern – newly created object 
  3. Method Invocation Pattern – object before dot 
  4. Indirect Invocation Pattern- manually passed as the first parameter 

So there are four possible values of ‘this’ inside a function, that depend on the way the function is called. Keep in mind that, an arrow function takes ‘this’ from the execution context and it does not have its own ‘this’ object. 

Watch 30 mins long video to master ‘this’ here: 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s