1.0.1 • Published 8 years ago
private-access v1.0.1
private-access
Automatic private symbol creator.
Installation
npm install --save private-access
Usage
NOTE This only works in ES6-compatible environments.
Include in any module that you want to have private access variables. Doing a one-line include / call can reduce the setup to almost none:
const _ = require('private-access').create();
Once a private access variable has been created, you can just use the dot-operator to create new Symbols:
person.js
// Try in the Node.JS REPL! ( Node v6.x.x )
const _ = require('private-access').create();
class Person {
constructor( name, ssn ) {
this.name = name;
this[_.ssn] = ssn;
}
speak() {
console.log('I like food!');
}
[_.whisper]() {
console.log('...waaayyy too much.');
}
}
index.js
// No access to `ssn` value or `whisper` method:
const Person = require('./person');
const person = new Person('John Doe', '123-12-1234');
console.log(`Hi, my name is ${person.name}`);
person.speak();
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT. Because.