write your own instanceof
2022年5月1日小于 1 分钟
instanceof
write your own Question
Do you know how instanceOf works ?
If so, please write you own 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
Code
/**
* @param {any} obj
* @param {target} target
* @return {boolean}
*/
function myInstanceOf(obj, target) {
// your code here
}