Classes

suggest change

Syntax

Remarks

Classes use JavaScript's prototype-based inheritance model, but they are more than textual shorthand for constructor functions. Class bodies run in strict mode, class declarations have a temporal dead zone, methods are non-enumerable, and a class constructor must be called with new. Modern classes also support public fields, private elements, and static initialization blocks.

class Example {
  constructor(value) {
    this.value = value;
  }

  someMethod() {
    return this.value;
  }
}

const example = new Example(42);
console.log(example.someMethod()); // 42
console.log(example instanceof Example); // true

Class Constructor

Class Inheritance

Static Methods

Getters and setters

Private Members

Dynamic Method Names

Methods

Managing Private Data with Classes

Class Name binding

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents