Skip to content

Instantly share code, notes, and snippets.

@tonkotsuboy
Created April 25, 2019 10:54
Show Gist options
  • Save tonkotsuboy/100da411af5378e40e018fbc2ad6f760 to your computer and use it in GitHub Desktop.
Save tonkotsuboy/100da411af5378e40e018fbc2ad6f760 to your computer and use it in GitHub Desktop.
プライベートフィールドの挙動確認
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