1.0.0 • Published 9 years ago

private-symbol v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

private-symbol

Private symbols for node

Usage

npm install private-symbol

and then:

var PrivateSymbol = require('private-symbol');

var myObj = {};
var symbol = PrivateSymbol();

myObj[symbol] = 123;

console.log(Object.getOwnPropertySymbols(myObj)); // nothing
  • PrivateSymbol([description]) — create symbol with description;
  • PrivateSymbol.for() works the same way as Symbol.for();
  • PrivateSymbol.keyFor() is NOT implemented.

Private symbols can be used for truly private properties:

var keyName = PrivateSymbol();
function MyConstructor(name) {
  this[keyName] = name;
}

MyConstructor.prototype.print = function () {
  console.log(this[keyName]);
};

License

MIT

1.0.0

9 years ago