this keyword

What is this?

JS is an OOP Language

this

=> Always refers to some object

method

=> A function defined inside an object (a function executed with .methodName())

function

=> All functions that are not methods

Cases where this is NOT window when defining function() {}

  1. this inside a method

  2. this inside a constructor function

When defining a method, you must always define it with function(){}!

ex)

The subject that called the eventListener becomes this!

  • It is passive!

    • Changes depending on who called it

Last updated