Implement myInstanceOf(value, Constructor) so it works like the instanceof operator.
myInstanceOf(value, Constructor) returns true if Constructor.prototype appears anywhere in value's prototype chain, and false otherwise. Primitives give false.
Like the real operator, it throws a TypeError if Constructor isn't a function, or if value is an object and Constructor.prototype isn't.
You can ignore Symbol.hasInstance and bound functions.
function myInstanceOf(value, Constructor) {
// your code
}
// myInstanceOf([], Array); // true
// myInstanceOf([], Object); // true: Object.prototype is further up the chain
// myInstanceOf(1, Number); // false: 1 is a primitive
// myInstanceOf({}, {}); // throws a TypeError: {} isn't a function
// myInstanceOf({}, () => {}); // throws a TypeError: an arrow function has no prototype
Solve it in the editor, with tests
The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…