Classes are special functions for creating objects.
new operator creates an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
When a function is invoked with
new in front of it, we call it a constructor call.
- ▪ create a new object,
- ▪ the object is
[[Prototype]]-linked to the function,
- ▪ the returned object is set as the
thisbinding for that function call &
- ▪ unless the function returns its own alternate object, the new-invoked function call will automatically return the newly constructed object.
constructor method is a special field for initializing an object created with a class.
The behaviour of a class can be replicated using a plain function.
extend keyword, a class can extend another class.
This removes the need to rewrite functionality you want to use across multiple classes.
If the child uses a contructor method, the
super keyword needs to be called before
this can be used.
It will invoke the parent's contructor method.
Public & Private
Fields are public by default.
Prefixing a field with a
# will make them private.
Private fields can only be accessed within the class.
constructor field cannot be private.