<script>
function instanceof1(target, fn) {
if (target == null) return false;
// 判断基本数据类型
const type = typeof target;
if (type !== 'function' && type !== 'object') {
return false;
}
let curTarget = target;
// 原型链最顶端为null
while (curTarget) {
if (curTarget.__proto__ == fn.prototype) {
return true;
}
curTarget = curTarget.__proto__;
}
return false;
}
console.log(instanceof1(function(){
},Object))
</script>