Implement instanceOf(value, Ctor). It returns true when Ctor.prototype appears anywhere in the prototype chain of value, and false otherwise.
The prototype chain is the list of objects you reach by asking an object for its prototype, then asking that prototype for its own, until you reach null.
- Don't use the
instanceofoperator orisPrototypeOf. - Primitives (
42,"hi",true,null,undefined) always givefalse. - Ignore any custom
Symbol.hasInstancemethod onCtor. Only the chain counts. - If
Ctoris not a function, throw aTypeError.
Input: class A {}; class B extends A {}; instanceOf(new B(), A)
Output: true
Input: instanceOf([], Map)
Output: false
Input: instanceOf(Object.create(null), Object)
Output: falsethe chain is empty, so Object.prototype is never reached