JavaScript Class Reference

blogphp18 thg5 2020
Javascript

www.w3schools.com

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

Gửi bài viết tới Facebook

Gửi hình ảnh