Introduction

Last updated 4 months ago

What is stampit

stampit is a JavaScript module which implements the stamp specification. Stamps are composable factory functions.

Think of stamps as classic classes but without any limits, boundaries, or rules.

The stamps brag large amount of features and things you can do with your objects and/or stamps.

Head straight to the Quick Start page for code examples.

Differences from classes

  • Inheritance

    • Classes

      • Classes do child+parent+parent+parent... inheritance chains. See picture above.

      • When you extend a class you link class prototypes.

    • Stamps

      • Stamp are single object + single prototype. See picture above.

      • When you "extend" you separately merge methods, separately merge properties, separately merge static properties, separately merge initializers (aka constructors), etc etc etc.

      • That's why it is not just inheritance, but special type of object composition. The stamp composition algorithm is standardized.

      • You can influence composition result with your code at runtime using the composers feature.

  • Object creation

    • Classes

      • In most programming languages you execute only one constructor per class.

      • To pass data to the parent constructor you have to manually call parent constructor this.super(data).

      • To create an object you need to use the new keyword: const object = new MyClass().

    • Stamps

      • Stamp executes every initializer (aka constructor) it has.

      • All initializers receive exactly the same set of arguments, no need to manually pass data.

      • The initializer execution sequence is the same as the stamp composition sequence.

      • To create an object you call stamp as a function: const object = MyStamp().

History

The original idea of Stamps belongs to Eric Elliott. See his first commit from 11 Feb 2013 in the stampit repository. Since then the idea evolved to the specification and a whole ecosystem of mini modules.

Using Stamps

Head straight to the Quick start for code examples.

Ecosystem

Stampit have a lot of helper modules. You can always find the list of official NPM packages here: https://www.npmjs.com/~stamp‚Äč

See more information on the Ecosystem page.