JavaScript Class Reference
JavaScript Classes
A class
is a type of function, but instead of using the keyword
function
to initiate it, we use the keyword
class
, and the properties are assigned inside a
constructor()
method:
Example
Create a Car class, and then create an object called "mycar" based on the Car class:
class Car { // Create a class
constructor(brand) { // Class constructor
this.carname = brand;
// Class body/properties
}
}
mycar = new Car("Ford"); // Create an object of Car
class
See Also:
Class Methods
Method | Description |
---|---|
constructor() | A special method for creating and initializing objects created within a class |
Class Keywords
Keyword | Description |
---|---|
extends | Extends a class (inherit) |
static | Defines a static method for a class |
super | Refers to the parent class |