2 minute read
The 'this' keyword represents a core part of object oriented programming in JavaScript. You have to understand how 'this' operates in different contexts and its rules to really maximize your use of the language. Rules of 'this':
Here's a basic chart of those prototype methods that operate on 'this':
Name | Parameters | Invocation |
---|---|---|
Call | this, a, b, c, d, ... | immediate |
Apply | thisArg,[a, b, c, ...] | immediate |
Bind | thisArg, a, b, c, ... | delayed |
Greater minds than mine have explained some of these concepts in much greater detail, so I will refer you to them for further reading.
Much like the keyword 'this' above, the keyword 'new' is essential to object oriented programming.
What does 'new' actually do though? This post breaks it down simply:
That's it! Keeping this in mind will really help you understand what context you're in when using the keyword 'this', which is why these two topics were bundled together. 'This' and 'new' are inseparable parts of JavaScript.