Wed. Dec 4th, 2019

Host your Website

Read and learn

FatCow Web Hosting $1.00/mo* Trust your web hosting to the #1 web host provider, GoDaddy!

JavaScript "this" word explained

1 min read

The word “this” is one of those misunderstood features in JavaScript given that people want it to behave like it does in other object oriented languages, when that simply is not the case.

Conceptually, there are only 3 things you need to remember, the word “this”:
1. is used inside functions,
2. is a reference to an object,
3. is set WHEN calling a function (not when the code is evaluated)

In practice, there are 3 ways you can set / use “this”:
1. implicitly as a method call,
2. explicitly through .call() or .bind()
3. constructor call .i.e when calling a function with the “new” word preceding it.

Copyright © All rights reserved. | Newsphere by AF themes.