JavaScript Sınıf Referansı
JavaScript Sınıfları
A class
bir işlev türüdür, ancak
function
onu başlatmak için
anahtar sözcüğü kullanmak yerine anahtar sözcüğünü kullanırız ve özellikler bir yöntemin class
içinde atanır
:constructor()
Örnek
Bir Car sınıfı oluşturun ve ardından Car sınıfını temel alan "mycar" adlı bir nesne oluşturun:
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
Sınıflar hakkında bir eğitim için JavaScript Sınıfları Eğitimimizi okuyun .
Sınıf Yöntemleri
Method | Description |
---|---|
constructor() | A special method for creating and initializing objects created within a class |
Sınıf Anahtar Kelimeleri
Keyword | Description |
---|---|
extends | Extends a class (inherit) |
static | Defines a static method for a class |
super | Refers to the parent class |