Skip to main content

this keyword ↔ Special variable which πŸ‘‰to "owner" of calling function

aka this

implicit parameter of functions

this is dynamic and depends on how function is called and value is only assigned when function is called

this Method​

πŸ‘‰ <Object called method\>

this Function Call​

πŸ‘‰ <undefined\> (in Strict Mode; Sloppy Mode πŸ‘‰ window)

this Arrow​

lexical this keyword πŸ‘‰ <surrounding function\>

this Event Listener​

πŸ‘‰ <DOM Element e handler attached to\>

this <script> tag​

πŸ‘‰ globalThis

this ECMAScript module​

πŸ‘‰ undefined

this CommonJS module​

πŸ‘‰ module.exports

image

!exception arrow functions do not get Args Object or this keyword

arrow functions borrow Args Object & this keyword from their closest regular function parent

References​

  1. new ↔ JS Operatorto call Constructor Function, assign this keyword & link to Prototype

  2. Factory Function ↔ function to return Object (w/o this keyword & new)

  3. **Creation Phase** ↔ Global EC created with window & this keyword pointing to it

  4. Arrow Function ↔ compact Anon Function w/o bind to this keyword or Args Object

  5. .call() ↔ Function Instance Method to invoke function with explicit this keyword [and optional Argument]

  6. .bind() ↔ Function Instance Method to fix this keyword for Method (with optional Argument), for new standalone fn

  7. --noImplicitThis ↔ to flag TSC to throw error when Type of this keyword unclear