Example 1 — Demo
Core idea.
JavaScript
class Fake {
static [Symbol.hasInstance](v) { return v === 1; }
}
console.log(1 instanceof Fake);
console.log(2 instanceof Fake);How It Works
- Custom. instanceof calls the static method.
- Result. Only 1 matches.
