- A class is a blueprint for creating objects. Each object made from it is an instance. Class names use PascalCase.
- The
constructorruns automatically when you create an instance withnew. Usethisto set up properties. - Methods are defined inside the class body without commas. Every instance shares them.
- Getters (
get name()) look like properties but are calculated. Setters (set name(v)) run on assignment, great for validation. staticmethods and properties belong to the class itself, not instances.- Private fields (
#name) can only be used inside the class. This is encapsulation. extendscreates a child class. Callsuper(...)in the child's constructor, andsuper.method()to reuse a parent's method. Children can override methods.thisdepends on how a function is called: method call → the object;new→ the new object; alone →undefined; arrow functions → the surroundingthis. Fix lostthiswith an arrow wrapper orbind.- Classes are built on prototypes: methods live on
ClassName.prototypeand are shared by all instances through the prototype chain.
Reading is step one
CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.