ES.next private name objects shim
Polyfill of ES.next private name objects. This implementation patches ES5
Object methods where possible to emulate private names as much as possible.
Still in some cases private names can be discovered:
Objectmethods from other JS contexts are used.
If properties are simply set like shown below, private names will be revealed by
foriteration:objectsecret = value
It is recommended to use
Object.definePropertiesfor defining private named properties. Those methods will make sure to mark property as non-enumerable so that such propertes won't be reavealed.
npm install name
var Name = require'name'var secret =// do not do `this[secret] = privateData` do following insteadObjectdefinePropertythis secretvalue: privateDatathisname = 'my'/*...*/ thissecret /*...*/var my =Objectkeysmy // => [ 'my' ]ObjectgetOwnPropertyNamesmy // => [ 'my' ]var names =for var name in my namespushnamenames // => [ 'my' ]