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/f07822cdb368fe8bdd49 to your computer and use it in GitHub Desktop.
Save brigand/f07822cdb368fe8bdd49 to your computer and use it in GitHub Desktop.
const KEY = Symbol('my key')
const fooProto = {
get key() {
return this[key]
}
};
function makeFoo() {
const foo = Object.create(fooProto);
foo[key] = 'my secret key';
return foo;
}
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