Loading topic
class keyword since ES2015. Before that, developers built the same structures by hand from constructor functions and prototypes. This chapter covers the two ways to write a class, a class decl5 min readthis means. You should also have read the previous chapter on declaring a class. Here we look at the constructor method and at wh4 min readnew, as covered in the previous chapters. You should also know arrow functions, template literals, and the basic idea that this refers to the object a function was called on.4 min readthis refers to the object a method is called on. The goal here is to show what the engine 5 min readthis.x = ... and that methods live on the class's prototype. It also uses extends and super() in a few short previews. Later chapters explain those two in full. Here you only need to know that a subclass constructor m5 min readprototype. Private fields get a full chapter later. Here they appear only where they interact with stati5 min readextends at a basic level. Earlier chapters covered all of these.5 min readthis inside a regular function depends on how the function is c5 min readprototype object. The next chapter covers super in detail. Here you will use super() only as much as extends needs it.5 min readextends and know that a subclass inherits methods through the prototype chain. You should also be comfortable with constructors, instance methods, class fields, and static members. Here we cover the super keyword. It has two forms. `supe4 min readextends builds a subclass and how class methods live on a prototype object. Both topics come earlier in this tutorial. You should also be able to run snippets in Node.js, because one example uses Node's vm module.5 min readError, Array, Map, and Set can be extended with extends like any class you write yourself. The subclass inherits the built-in's internal behavior: the stack trace on an error, the auto-updating length on an array, the hash table inside a map. This chapter covers 4 min readextends and super() work, how methods live on the prototype, and how class fields are initialized. You will use new.target to build base classes that cannot be instantiated directly but can still be extended. You will also see where this pattern stops 5 min readextends and super work, how the prototype chain resolves method lookups, and how instanceof checks it. It shows how to add reusable behavior to a class without forcing every class into a single inheritance tree.4 min read