stampit API
Search…
@stamp/instanceof
Enables obj instanceof MyStamp in ES6 environments
1
const InstanceOf = require('@stamp/instanceof');
2
// or
3
import InstanceOf from '@stamp/instanceof';
Copied!
It uses the well known Symbol hasInstance to test instance.

Example

Create a stamp:
1
let MyStamp = compose({
2
properties: { ... },
3
initializers: [function () { ... }]
4
});
Copied!
The following doesn't work:
1
const obj = MyStamp();
2
obj instanceof MyStamp === false;
Copied!
Compose the InstanceOf to your stamp:
1
MyStamp = MyStamp.compose(InstanceOf);
Copied!
Now it works:
1
const myObject = MyStamp();
2
obj instanceof MyStamp === true;
Copied!

Notes

  • We do not recommend to use instanceof in JavaScript in general.
Last modified 3yr ago
Copy link
Contents
Example
Notes