Makes all properties and optional methods private
Inspired by the
private-class module. NOTE! Requires WeakMap, thus won't work in IE10.
This stamp (aka behavior) will create a proxy object. Its methods would delegate all the calls to the original object instance.
All the properties are made private. Methods privatization is optional and can be done via the
privatizeMethods static function.
;;const AuthWithPrivateProperties = Auth;const AuthWithPrivatePropertiesAndMethod = Auth;
Or if you don't want to import the stamp you can import only the method:
;const AuthWithPrivatePropertiesAndMethod = Auth;
Every property you assign in the initializers will be private.
const Original =;foo === undefined;bar === undefined;
This is a neat feature since you don't need to use JS closures to hide variables from external users.
let accessPassword accessSetPassword;const Original =;// Add Privatize behavior, additionally protect the 'setPassword' methodconst Stamp = Original;// All properties and the method 'setPassword' are undefinedconst instance = ;;;// But the 'checkAccess' method have access to the properties and 'setPassword'instance;;;
Smart use of configuration
If you ever was thinking how cool if it was having
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.
;const ConfiguredPrivatize = Privatize;
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.
@stamp/privatize module knows about and relies on other ecosystem stamps implementation. This means that other
@stamp/* ecosystem stamps should know nothing about
@stamp/privatize. But opposite is acceptable.