Skip to content

Instantly share code, notes, and snippets.

@edwardkenfox
Last active October 12, 2018 02:37
Show Gist options
  • Save edwardkenfox/e933feb47fb7c786f6ac5010e47344d0 to your computer and use it in GitHub Desktop.
Save edwardkenfox/e933feb47fb7c786f6ac5010e47344d0 to your computer and use it in GitHub Desktop.
private method in JavaScript using Symbols
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