Classes
In JavaScript, a class is a kind of function.
What class A{...}
construct really does is:
Creates a function named
A
, that becomes the result of the class declaration. The function code is taken from theconstructor
method.Stores class methods in
A.prototype
Basic syntax
class MyClass {
prop = value; // property
constructor(...) { // constructor
// ...
}
method(...) {} // method
get something(...) {} // getter method
set something(...) {} // setter method
[Symbol.iterator]() {} // method with computed name (symbol here)
// ...
}