Created
April 25, 2019 10:54
-
-
Save tonkotsuboy/100da411af5378e40e018fbc2ad6f760 to your computer and use it in GitHub Desktop.
プライベートフィールドの挙動確認
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
foo = "パブリックなフィールド"; | |
#bar = "プライベートなフィールド"; | |
constructor() { | |
console.log(this.foo); | |
console.log(this.#bar); // クラス内からはアクセス可能 | |
} | |
} | |
const myInstance = new MyClass(); | |
console.log(myInstance.foo); | |
console.log(myInstance.#bar); // エラー!クラス外からアクセス不可能 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment