Private registry for classes
$ npm install @absolunet/private-registry
const __ = require('@absolunet/private-registry');
class Foo {
constructor(id) {
__(this).set({
id: `id::${id}`,
seed: Math.random()
});
}
set bar(id) {
__(this).set('id', `id::${id}`);
}
get bar() {
return `My id is ${__(this).get('id')}`;
}
get bar2() {
const { id, seed } = __(this).get();
return `${id}::${seed}`;
}
}
const a = new Foo('123');
const b = new Foo('456');
console.log(a.bar);
console.log(b.bar);
console.log(b.bar2);
// My id is id::123
// My id is id::456
// id::456::0.0337644127126262
Return Object
of all registry entries
Return value of a registry's entry
Required
Type: String
Entry's name.
Set all entries from object into the registry
Required
Type: Object
Object which each entry will be added to the registry
Set entry into the registry
Required
Type: String
Entry's name.
Required
Type: Any
Value of the entry
MIT © Absolunet