封装instanceof

递归实现 instanceof 功能

// 封装 instanceof
function myInstanceof(obj, type) {
     
    if (obj === null || !type) return false
    else if (obj.constructor.name === type.name) return true
    let l = obj.__proto__
    return myInstanceof(l, type)
}
// 验证
const arr = function () {
     }
const b = myInstanceof(arr, Function)
console.log(b)

你可能感兴趣的:(js)