Forked from davidrhyswhite/es6-private-methods-with-symbols.js
Created
April 15, 2018 04:23
-
-
Save ruxandrafed/eb9b8fd640d9a9683163cd23308085e0 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
const privateMethod = Symbol('privateMethod'); | |
export default class Service { | |
constructor () { | |
this.say = "Hello"; | |
} | |
[privateMethod] () { | |
console.log(this.say); | |
} | |
publicMethod () { | |
this[privateMethod]() | |
} | |
} | |
// Uncaught TypeError: (intermediate value).privateMethod is not a function | |
new Service().privateMethod() | |
// Uncaught TypeError: (intermediate value)[Symbol(...)] is not a function | |
new Service()[Symbol('privateMethod')](); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment