Composers
const InstanceOf = stampit.composers(({ stamp, composables }) => {
if (!stamp.compose.methods) stamp.compose.methods = {} // mutating stamp
stamp.compose.methods.getStamp = () => stamp // mutating stamp
Object.defineProperty(stamp, Symbol.hasInstance, { // mutating stamp
value(obj) {
return obj && typeof obj.getStamp === 'function' && obj.getStamp() === stamp
}
})
})
console.log(InstanceOf() instanceof InstanceOf) // true
console.log(InstanceOf().getStamp() === InstanceOf) // true
const Stamp = InstanceOf.props({ anything: 1 })
console.log(Stamp() instanceof Stamp) // true
console.log(Stamp().getStamp() === Stamp) // true
console.log(Stamp() instanceof InstanceOf) // false
console.log(InstanceOf() instanceof Stamp) // falseDescriptor merging algorithm
Composer arguments
Other ways to add composers
Last updated