Methods
Last updated
Last updated
You can add methods (aka functions) to the objects created from your stamps.
All the methods are attached to object's prototype.
Moreover, the entire methods
becomes the prototype.
If you compose the stamp above with any other stamp, then object instances created from it will also have the .debug
method.
The methods are copied by assignment. In other words - by reference using Object.assign
.
NOTE
Exactly the same stamp can be created in few ways. Here they all are.
In case of conflicts the last composed method wins. To avoid method collision use the stamp. To make sure a method is implemented use the stamp.
When using the stamp it creates a proxy object and returns from the factory. This means that logger.__proto__ === Logger.compose.methods
or logger.__proto__.debug === Logger.compose.methods.debug
will no longer be true
.