- Prototype
- Class
class ClassName {
functionName() {}
constructor() {}
}
let variable = new ClassName();
- Object
let variable = new ClassName();
- Inheritance
class ClassName1 {}
class ClassName2 extends ClassName1 {
// Call constructors and functions of parent class
super(arguments);
super.functionName(arguments);
}
- Overriding Constructor
class ClassName2 extends ClassName1 {
// Created automatically
constructor(...arguments) {
super(...arguments);
}
// Custom
constructor() {
super();
// this statements must be written after super()
}
}
- Static Methods
class ClassName {
static functionName() {
return value;
}
}
// Calling
ClassName.functionName();
- Getter, Setter
class ClassName {
get variable() {
return this._variable;
}
set variable(newVariable) {
this._variable = newVariable;
}
}
- Others
variable instanceof className
=> Returns boolean value true if object is a instance of class or any other class inheriting from it