Intro ECMAScript の Private Class Field の仕様策定と各ブラウザの実装が進んでいる。 これにより、従来の JS にはなかった Class の Private フィールドが使えるようになる。 提案されている構文や、挙動について解説する。 Class Field Declaration まず前提として、現状の Class の フィールドはコンストラクタで定義する必要がある。 例えば count フィールドを持つ Counter クラスを定義した場合、以下のようになる。 class Counter { constructor() { this.count = 0 } increment() { this.count ++ } display() { console.log(this.count) } } const c = new Counter() c.in
![Private Class Field の導入に伴う JS の構文拡張 | blog.jxck.io](https://cdn-ak-scissors.b.st-hatena.com/image/square/25f705929f7e98ea08f049f3c57b5de57a1b3ba0/height=288;version=1;width=512/https%3A%2F%2Fblog.jxck.io%2Fassets%2Fimg%2Fjxck.600x600.png)