90. 实现`instanceof`

中等难度  -通过 / -执行

你知道 instanceOf 是如何工作的吗 ?

如果直到的话,请实现一个 myInstanceOf()

class A {}
class B extends A {}

const b = new B()
myInstanceOf(b, B) // true
myInstanceOf(b, A) // true
myInstanceOf(b, Object) // true

function C() {}
myInstanceOf(b, C) // false
C.prototype = B.prototype
myInstanceOf(b, C) // true
C.prototype = {}
myInstanceOf(b, C) // false

始终思考更好的解决办法

(51)