Stampit implements the stamp specification: small composable factory functions for building objects via delegation, concatenation, or functional patterns.
Overview
Stampit is a compact JavaScript module that implements standardized composable factory functions called stamps. Instead of classic class inheritance chains, you merge methods, properties, static properties, and initializers from reusable stamps, then create instances by calling the stamp as a function rather than using new.
The library supports prototypal inheritance styles—delegation, concatenation, and functional composition—so you can combine behaviors without deep parent chains. Every initializer in a composed stamp runs with the same arguments, in composition order, which differs from manually calling super in class constructors. A composers feature lets you influence composition at runtime.
Stampit ships as a reference implementation of the stamp specification, with an ecosystem of related npm helper packages documented on the project site. Documentation contrasts stamps with classes using examples that split concerns such as Point, Circle, Colored, Tagged, and drawable graph primitives into separate composable units.
Install via npm for current major versions; the API is documented on the official site alongside quick-start examples and extended mini-blog tutorials.
Key features
- Composable stamp factory functions
- Multiple prototypal inheritance styles
- Runtime composition via composers
- Shared initializer argument lists
- Methods and properties merging
- Specification-aligned implementation
- Helper ecosystem on npm
- Function-call object creation
Use cases
- Build objects from reusable behaviors
- Avoid deep class inheritance trees
- Mix methods and privileged data patterns
- Model has-a and is-a composition
- Prototype object-oriented designs in JavaScript