package
Create objects from reusable, composable behaviors.
npm install stampitGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
68.7 kB
Includes dependencies.
Latest published Jul 2, 2026
latest
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.
Find many more examples in this series of mini blog posts or on the official website.
import stampit from "stampit";
const Character = stampit({
props: {
name: null,
health: 100,
},
init({ name = this.name }) {
this.name = name;
},
});
const Fighter = Character.compose({
// inheriting
props: {
stamina: 100,
},
init({ stamina = this.stamina }) {
this.stamina = stamina;
},
methods: {
npm i stampit@1npm i stampit@2 Breaking changesnpm i stampit@3 Breaking changes. Compatible with the stamp specification <= 1.4npm i stampit@4 Breaking changes. Compatible with the stamp specification v1.5Prototypal 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;
};
For more examples see the API or the Fun With Stamps mini-blog series.
npm tnpm run test:benchmarkkoresar
kore.sar@gmail.com
npm i stampit Breaking changes. Compatible with the stamp specification v1.5