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.
- Function Invocation Pattern – global object
- Constructor Invocation Pattern – newly created object
- Method Invocation Pattern – object before dot
- 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