# stampit

> Create objects from reusable, composable behaviors.

Latest version **5.1.0** (published 2026-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install stampit
pnpm add stampit
yarn add stampit
bun add stampit
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2026-07-02 |
| First published | 2013-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 68.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3006 |
| Maintainers | ericelliott, koresar |
| Keywords | object, prototype, object oriented, browser, inheritance, oop, node, factory, class, stamp, mixin |

## Links

- npm: https://www.npmjs.com/package/stampit
- Repository: https://github.com/stampit-org/stampit
- Homepage: https://stampit.js.org
- Issues: https://github.com/stampit-org/stampit/issues
- npm.io page: https://npm.io/package/stampit

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 5.1.0 (latest) — 2026-07-02
- 5.0.5-next (next) — 2025-09-02
- 3.0.0-rc.11 (rc) — 2016-09-21
- 5.0.1 — 2025-10-23
- 5.0.0 — 2025-10-05
- 5.0.4-next — 2024-11-20
- 5.0.3-next — 2024-11-20
- 5.0.1-next — 2024-11-20
- 5.0.0-next — 2024-11-20
- 4.3.2 — 2021-03-30
- 4.3.1 — 2019-12-04
- 4.3.0 — 2019-09-15
- 4.2.0 — 2018-09-16
- 4.1.2 — 2018-06-08
- 4.1.1 — 2018-03-08
- … 55 more at https://npm.io/package/stampit/versions

## README

<p align="center">
<img src="https://raw.githubusercontent.com/stampit-org/stampit-logo/master/stampit-logo.png" alt="stampit" width="160" />
</p>

# Stampit [![npm](https://img.shields.io/npm/dm/stampit.svg)](https://www.npmjs.com/package/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](https://github.com/stampit-org/stamp-specification) 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](https://medium.com/@koresar/fun-with-stamps-episode-1-stamp-basics-e0627d81efe0) or on the [official website](https://stampit.js.org/api/quick-start).

## Example

```js
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

- **v1**. `npm i stampit@1`
- **v2**. `npm i stampit@2` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/2.0)
- **v3**. `npm i stampit@3` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/v3.0.0). Compatible with the [stamp specification](https://github.com/stampit-org/stamp-specification) <= 1.4
- **v4**. `npm i stampit@4` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/v4.0.0). Compatible with the [stamp specification](https://github.com/stampit-org/stamp-specification) v1.5
- **v5**. `npm i stampit` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/v5.0.0). Compatible with the [stamp specification](https://github.com/stampit-org/stamp-specification) v1.5

## Install

[![NPM](https://nodei.co/npm/stampit.png?compact=true)](https://www.npmjs.com/package/stampit)

## API

See https://stampit.js.org

# 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.

```js
// 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 instance
const 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](https://stampit.js.org) or the [Fun With Stamps](https://medium.com/@koresar/fun-with-stamps-episode-1-stamp-basics-e0627d81efe0) mini-blog series.

# Development

### Unit tests

```
npm t
```

### Benchmark tests

```
npm run test:benchmark
```

---
_Source: https://npm.io/package/stampit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
