JavaScript Essentials: Objects

https://codeburst.io/javascript-essentials-objects-56373a1a6bfb

In this blog I have found a clear explication for the this in JS

What is This?

I’m literally referring to this in JavaScript. This is perhaps the part of JS that confuses people the most.

This — a variable created by JavaScript that points to an object.
this is created when an execution context is created ( i.e running a function )

1. We understand this is an object given to us by JavaScript when a function is run.

2. What determines the object this points to? That depends on how the function is called.

  • Implicit Binding — if the function is called with a containing object then this refers to that object. i.e person.greet
    When a function is called as a method of an object, that function’s this argument is set to the object the method is called on.

Leave a comment