JavaScript Class Reference Manual
- Previous Page JS Boolean
- Next Page JS Date
JavaScript Class
A class is a type of function, but we do not use the keyword function to initialize it, instead we use the keyword class, and assign properties in the constructor() method:
Instance
Create a Car class and then create an object named "mycar" based on this Car class:
class Car { // Create a class constructor(brand) { // Class constructor this.carname = brand; // Class body, attribute } } mycar = new Car("Ford"); // Create a Car class object
For knowledge about classes, please read our JavaScript Class Tutorial.
Class Method
Method | Description |
---|---|
constructor() | A special method used to create and initialize objects created in the class. |
Class Keyword
Keyword | Description |
---|---|
extends | Extend a class (inherit). |
static | Define static methods for the class. |
super | Reference the superclass. |
- Previous Page JS Boolean
- Next Page JS Date