function instanceof_myself(leftValue,rightValue) {
let rightPrototype = rightValue.prototype; //获取右侧构造函数对应的原型
let leftProto=leftValue.__proto__;//获取左侧实例对应的原型
while(true) {
if (leftProto === null) {
return false;
} else if (leftProto === rightPrototype) {
return true;
}
leftProto=leftProto.__proto__;
}
}
实现instanceof方法
最新推荐文章于 2023-03-17 18:11:08 发布