Graduated in Digital Media M.Sc. now developing the next generation of educational software. Since a while I develop full stack in Javascript using Meteor. Love fitness and Muay Thai after work.
Create a given ES6 class with private members using Proxy and closures. Keeps class code clean, encourages SRP and DRY.
🔒 Javascript Class-Privacy
Lean dry no-dep srp :cup: package to create instances from classes with defined private members
Keep your classes clean und use this instead to define private properties
Uses proxies to hide information.
Installation and basic usage
Install this package via NPM like
$ npm install class-privacy
The packages exports only one function, that acts similar to an abstract factory
You can pass in a decide function to define rules (e.g. whitelist)
for members. The created factory can be used to create (proxies to) instances that
contain only the public members.
importcreateFactoryfrom'class-privacy'exportclassPerson{constructor({ name, age }){this.name=namethis.age=age}greet(){return`Hello, my name is "${this.name}". I am ${this.age} years old.`}}// make
Uses Proxy to control private/public fields or methods of any JavaScript class. Real private and 100% not accessible. Works with ES6 classes as well as "Classic" classes.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
jankapunkt / js-class-privacy
Create a given ES6 class with private members using Proxy and closures. Keeps class code clean, encourages SRP and DRY.
Lean dry no-dep srp :cup: package to create instances from classes with defined private members Keep your classes clean und use this instead to define private properties Uses proxies to hide information.
Installation and basic usage
Install this package via NPM like
The packages exports only one function, that acts similar to an abstract factory You can pass in a
decide
function to define rules (e.g. whitelist) for members. The created factory can be used to create (proxies to) instances that contain only the public members.Uses Proxy to control private/public fields or methods of any JavaScript class. Real private and 100% not accessible. Works with ES6 classes as well as "Classic" classes.