0
0

【JS/ES6】関数(メソッド)の宣言の仕方(書き方)

Posted at

はじめに

関数を宣言するときに忘れそうになるので備忘録メモ。

通常の宣言パターン

const 関数名 = function(引数){
  // ここに処理
};

const 関数名 = (引数) => {
  // ここに処理
};

プロパティを持たせての宣言パターン

const オブジェクト名 = {
  プロパティ名1: 値1,
  プロパティ名2: () =>{
    // ここに処理
  }
}

オブジェクト名.プロパティ名2();

クラス定義

class クラス名{
  constructor(引数){
    this.変数名 = 値;
  }

  メソッド1(){
  }

  メソッド2(){
    this.メソッド1();
  }
}

//クラスからインスタンスを生成
const インスタンス名 = new クラス名();

クラスAを継承したクラスB

class A{
  constructor(){
  }
}

class B extends A{
  constructor(){
    super();
    //コンストラクタをオーバーライドする際は親クラスのコンストラクタを呼び出す
  }
}

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0