====== JavaScript 構文 ======
===== ES6 class static variable =====
Chrome v72、V8 v7.2 から class の static メンバー変数をサポートしているので以下のような書き方ができる。\\
ただし、この構文は Mobile Chrome では 2019/09/12 現在 v77 であるが動作しなかった。\\
FireFox などでも勿論動作しないので注意が必要である。\\
class Counter {
static _count = 0;
static increment() {
return this._count++;
}
}
では、Mobile でも動作する static メンバー変数はどう定義するか?\\
それはとても簡単である。以下のように static メンバー関数内でクラスメンバーとして初期化するだけである。\\
class Counter {
static increment() {
this._count = this._count || 0;
return this._count++;
}
}
==== 参考文献 ====
[[https://v8.dev/features/class-fields|Public and private class fields · V8]]\\
===== 参考文献 =====
[[https://www.webprofessional.jp/shorthand-javascript-techniques/|あなたが知らないJavaScriptの便利すぎるショートハンド19選 - WPJ]]\\