class Foo {}
const foo = new Foo();
console.log(foo instanceof Foo === Foo[Symbol.hasInstance](foo)); // trueFunction.prototype[Symbol.hasInstance]() / notebook
Function.prototype[Symbol.hasInstance]()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
class Foo {
static [Symbol.hasInstance](value) {
// A custom implementation
return false;
}
}
const foo = new Foo();
console.log(foo instanceof Foo); // false
console.log(Function.prototype[Symbol.hasInstance].call(Foo, foo)); // true