@stamp/instanceof

Enables obj instanceof MyStamp in ES6 environments

const InstanceOf = require('@stamp/instanceof');
// or
import InstanceOf from '@stamp/instanceof';

It uses the well known Symbol hasInstance to test instance.

Example

Create a stamp:

let MyStamp = compose({
  properties: { ... },
  initializers: [function () { ... }]
});

The following doesn't work:

const obj = MyStamp();
obj instanceof MyStamp === false;

Compose the InstanceOf to your stamp:

MyStamp = MyStamp.compose(InstanceOf);

Now it works:

const myObject = MyStamp();
obj instanceof MyStamp === true;

Notes

  • We do not recommend to use instanceof in JavaScript in general.

Last updated