Skip to content

Instantly share code, notes, and snippets.

@brigand
Forked from yoshuawuyts/symbol-private-props.js
Last active August 29, 2015 14:20
Show Gist options
  • Save brigand/3c44f31b663894a0d0d1 to your computer and use it in GitHub Desktop.
Save brigand/3c44f31b663894a0d0d1 to your computer and use it in GitHub Desktop.
const KEY = Symbol('my key')
function makeFoo(){
return {
[KEY]: 'my secret key',
get key(){
return this[KEY];
}
};
}
const foo = makeFoo();
console.log(foo.key)
// => 'my secret key'
console.log(foo[KEY])
// => 'my secret key'
console.log(foo[Symbol('my key')])
// => undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment