Last active
October 12, 2018 02:37
-
-
Save edwardkenfox/e933feb47fb7c786f6ac5010e47344d0 to your computer and use it in GitHub Desktop.
private method in JavaScript using Symbols
This file contains hidden or 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 obj = (() => { | |
const privateName = Symbol('privateName') | |
return { | |
[privateName]() { | |
return 'Foo' | |
}, | |
publicName() { | |
return `${this[privateName]()} Bar` | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment