Learn JavaScript

Lesson 2 of 9 · this, Prototypes and Classes

Module 9 · this, Prototypes and Classes

Every Rule for this, and Every Piece of Class Syntax, One by One

Free with an accountReading

Kenji is building a shop app with a team. One teammate writes classes, another writes constructor functions, a third passes methods to timers. Every bug report this week says "this is undefined" or "this.price is NaN". The rules are not hard. There are just several of them, and each call form follows one.

Checking what this lesson needs for you…

What is inside Every Rule for this, and Every Piece of Class Syntax, One by One

  1. The method call
  2. The plain call
  3. call and apply
  4. bind
  5. new
  6. The arrow's lexical this
  7. Object.create and Object.getPrototypeOf
  8. Constructor functions and .prototype
  9. Class syntax: constructor and methods
  10. Class fields
  11. static
  12. Getters and setters
  13. extends and super
  14. Private fields with #
  15. instanceof
  16. class is sugar over prototypes
  17. Where the sugar leaks: methods are not bound
  18. Which this do I get?