stampit-org/stampit
{ "createdAt": "2013-02-10T16:20:49Z", "defaultBranch": "master", "description": "OOP is better with stamps: Composable object factories.", "fullName": "stampit-org/stampit", "homepage": "https://stampit.js.org", "language": "JavaScript", "name": "stampit", "pushedAt": "2025-10-23T05:39:14Z", "stargazersCount": 3015, "topics": [ "class", "composition", "dependency-injection", "factory", "javascript", "object-oriented", "oop", "stamps" ], "updatedAt": "2025-11-14T04:48:54Z", "url": "https://github.com/stampit-org/stampit"}
Stampit 
Section titled “Stampit ”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.
Example
Section titled “Example”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: { fight() { console.log(`${this.name} takes a mighty swing!`); this.stamina--; }, },});
const Mage = Character.compose({ // inheriting props: { mana: 100, }, init({ mana = this.mana }) { this.mana = mana; }, methods: { cast() { console.log(`${this.name} casts a fireball!`); this.mana--; }, },});
const Paladin = stampit(Mage, Fighter); // as simple as that!
const fighter = Fighter({ name: "Thumper" });fighter.fight();const mage = Mage({ name: "Zapper" });mage.cast();const paladin = Paladin({ name: "Roland", stamina: 50, mana: 50 });paladin.fight();paladin.cast();
console.log(Paladin.compose.properties); // { name: null, health: 100, stamina: 100, mana: 100 }console.log(Paladin.compose.methods); // { fight: [Function: fight], cast: [Function: cast] }Status
Section titled “Status”- v1.
npm i stampit@1 - v2.
npm i stampit@2Breaking changes - v3.
npm i stampit@3Breaking changes. Compatible with the stamp specification <= 1.4 - v4.
npm i stampit@4Breaking changes. Compatible with the stamp specification v1.5 - v5.
npm i stampitBreaking changes. Compatible with the stamp specification v1.5
Install
Section titled “Install”What’s the Point?
Section titled “What’s the Point?”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; }; },});
// Here's a stamp with public methods, and some state:const Membership = stampit({ props: { members: {}, }, methods: { add(member) { this.members[member.name] = member; return this; }, getMember(name) { return this.members[name]; }, },});
// Let's set some defaults:const Defaults = stampit({ props: { name: "The Saloon", specials: "Whisky, Gin, Tequila", }, init({ name, specials }) { this.name = name || this.name; this.specials = specials || this.specials; },});
// Classical inheritance has nothing on this.// No parent/child coupling. No deep inheritance hierarchies.// Just good, clean code reusability.const Bar = stampit(Defaults, Availability, Membership);
// Create an object instanceconst myBar = Bar({ name: "Moe's" });
// Silly, but proves that everything is as it should be.myBar.add({ name: "Homer" }).open().getMember("Homer");For more examples see the API or the Fun With Stamps mini-blog series.
Development
Section titled “Development”Unit tests
Section titled “Unit tests”npm tBenchmark tests
Section titled “Benchmark tests”npm run test:benchmark