stampit API
  • Introduction
  • Essentials
    • What is a Stamp
    • Installation
    • Specification
      • Merging algorithm
      • Object creation internals
    • FAQ
  • API
    • Quick start
    • Basics
    • Methods
    • Properties
    • Deep properties
    • Initializers
    • Static properties
    • Static deep properties
    • Configuration
    • Deep configuration
    • Composers
    • Property descriptors
    • Static property descriptors
    • Name
  • Ecosystem
    • Ecosystem Overview
    • @stamp/collision
    • @stamp/required
    • @stamp/privatize
    • @stamp/named (DEPRECATED)
    • @stamp/instanceof
Powered by GitBook
On this page
  • Example
  • Notes
  1. Ecosystem

@stamp/instanceof

Previous@stamp/named (DEPRECATED)

Last updated 6 years ago

Enables obj instanceof MyStamp in ES6 environments

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

It uses the 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.

well known Symbol hasInstance