Static properties

Static properties are properties attached to the stamp itself.

const PrintMyself = stampit({
  statics: {
    myProperty: 'foo',

    printMyself() {
      console.log(this)
    }
  }
})

PrintMyself.myProperty === 'foo'

PrintMyself.printMyself() // call the function without creating an instance of the stamp

If you compose the stamp above with any other stamp, then it will have the printMyself method too.

const Server = stampit(PrintMyself, {
  ...
})

Server.printMyself()

Fun fact

Stampit's chain methods are all regular static properties: Stamp.props().methods().init().statics().conf()... etc

Using statics to compose in your own way

Often static methods are used to tweak a stamp, to compose more metadata in a domain specific way.

The example above exposes a static function which controls access to the setFactor method of your object instances.

Descriptor merging algorithm

The static properties are copied by assignment. In other words - by reference using Object.assign.

In case of conflicts the last composed property wins.

Other ways to add static properties

Exactly the same stamp can be created in few ways. Here they all are.

Last updated