Every property you assign in the initializers will be private.
This is a neat feature since you don't need to use JS closures to hide variables from external users.
Example
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.
const Original = compose({
initializers: function () {
this.foo = 42; // THIS WILL BE PRIVATE
this.bar = function () {}; // THIS WILL BE PRIVATE TOO
}
});
Original().foo === undefined;
Original().bar === undefined;
let accessPassword, accessSetPassword;
const Original = 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
const Stamp = Original.compose(Privatize).privatizeMethods('setPassword');
// All properties and the method 'setPassword' are undefined
const instance = 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);