Create objects from reusable, composable behaviors
Stampit is a 1.3KB gzipped (or 4.8K minified) JavaScript module which supports three different kinds of prototypal inheritance (delegation, concatenation, and functional) to let you inherit behavior in a way that is much more powerful and flexible than any other Object Oriented Programming model.
Stamps are standardised composable factory functions. Stampit is a handy implementation of the specification featuring friendly API.
Prototypal OO is great, and JavaScript's capabilities give us some really powerful tools to explore it, but it could be easier to use.
Basic questions like "how do I inherit privileged methods and private data?" and
"what are some good alternatives to inheritance hierarchies?" are stumpers for many JavaScript users.
Let's answer both of these questions at the same time.
// Some privileged methods with some private data.const Availability = stampit({ init() { let isOpen = false; // private this.open = function open() { isOpen = true; return this; }; this.close = function close() { isOpen = false; return this; }; this.isOpen = function isOpenMethod() { return isOpen; };