JavaScriptクラスリファレンス
JavaScriptクラス
Aclass
は関数の一種ですが、キーワード
function
を使用して開始する代わりに、キーワードを使用し
class
、プロパティは
constructor()
メソッド内で割り当てられます。
例
Carクラスを作成し、Carクラスに基づいて「mycar」というオブジェクトを作成します。
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
クラスに関するチュートリアルについては、JavaScriptクラスチュートリアルをお読みください。
クラスメソッド
Method | Description |
---|---|
constructor() | A special method for creating and initializing objects created within a class |
クラスキーワード
Keyword | Description |
---|---|
extends | Extends a class (inherit) |
static | Defines a static method for a class |
super | Refers to the parent class |