Every property you assign in the initializers will be private.
constOriginal=compose({initializers:function () {this.foo =42; // THIS WILL BE PRIVATEthis.bar=function () {}; // THIS WILL BE PRIVATE TOO }});Original().foo ===undefined; Original().bar ===undefined;
This is a neat feature since you don't need to use JS closures to hide variables from external users.
Example
let accessPassword, accessSetPassword;constOriginal=compose({ properties: {password:'123'}, methods: {setPassword(value) { this.password = value; },checkAccess() { accessPassword =this.password; accessSetPassword =this.setPassword; } }});// Add Privatize behavior, additionally protect the 'setPassword' method constStamp=Original.compose(Privatize).privatizeMethods('setPassword');// All properties and the method 'setPassword' are undefinedconstinstance=Stamp();expect(instance.password).toBeUndefined();expect(instance.setPassword).toBeUndefined();// But the 'checkAccess' method have access to the properties and 'setPassword'instance.checkAccess();expect(accessPassword).toBe('123');expect(accessSetPassword).toBe(Original.compose.methods.setPassword);
Smart use of configuration
If you ever was thinking how cool if it was having configuration (and deepConfiguration) accessible in your method without explicitly exposing it through initializer, with privatize stamp you can simply do this. First make your own extension to Private stamp.
Then you can use for your other stamps and being able to access configuration within any method while still have it hidden from public sight.
compose(ConfiguredPrivatize, { configuration: { secret:'mykey' }, methods: {encrypt(value) {const { secret } =this.stampConfiguration;// run encryption with secret while it's still hidden from outside } }})