Dokumentacja klas JavaScript
Klasy JavaScript
A class
jest rodzajem funkcji, ale zamiast używać słowa kluczowego
function
do jej inicjowania, używamy słowa kluczowego
class
, a właściwości są przypisywane wewnątrz
constructor()
metody:
Przykład
Utwórz klasę Car, a następnie utwórz obiekt o nazwie „mycar” na podstawie klasy Car:
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
Samouczek dotyczący klas znajdziesz w naszym samouczku dotyczącym klas JavaScript .
Metody klas
Method | Description |
---|---|
constructor() | A special method for creating and initializing objects created within a class |
Słowa kluczowe klas
Keyword | Description |
---|---|
extends | Extends a class (inherit) |
static | Defines a static method for a class |
super | Refers to the parent class |