JavaScript this keyword

Gerard Sans
Sons of JavaScript
Published in
1 min readNov 28, 2014

this usages

While using JavaScript one wonders what the this keyword means on different scenarios.

You may start using it on a click event of a DOM element, maybe using the constructor pattern and the list goes on. Then you start seeing it being used in more advanced scenarios where this is changed behind the scenes.

These are the uses of this you should be familiar with:

Pointing to the global scope (window)

Pointing to an object literal

Pointing to a new object using new keyword

Pointing to an object using call or apply

Used on a DOM event handler

Reference: Mozilla JavaScript Reference link

--

--

Gerard Sans
Sons of JavaScript

Helping Devs to succeed #AI #web3 / ex @AWSCloud / Just be AWSome / MC Speaker Trainer Community Leader @web3_london / @ReactEurope @ReactiveConf @ngcruise