JavaScript superで親クラスの静的メソッドを呼び出すサンプル

環境
Windows 10 home 64bit
Google Chrome 107.0.5304.122

構文
class 親クラス{
static メソッド名(){処理コード1}
}
class 子クラス extends 親クラス{
static メソッド名(){処理コード2}
}
子クラス名.静的メソッド名();
静的メソッドでの super の呼び出します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
class Rectangle {
static funA() {
console.log("AA");
return 'AA';
}
}
class Square extends Rectangle {
static funB() {
console.log(super.funA() + ' 88');
return super.funA() + ' 88';
}
}
Square.funB();
class Rectangle { static funA() { console.log("AA"); return 'AA'; } } class Square extends Rectangle { static funB() { console.log(super.funA() + ' 88'); return super.funA() + ' 88'; } } Square.funB();
class Rectangle {
  static funA() {
     console.log("AA");
    return 'AA';
  }
}

class Square extends Rectangle {
  static funB() {
    console.log(super.funA() + ' 88');
    return super.funA() + ' 88';
  }
}
Square.funB();

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
> "AA"
> "AA 88"
> "AA"
> "AA" > "AA 88" > "AA"
> "AA"
> "AA 88"
> "AA"

 

JavaScript

Posted by arkgame