https://www.ibm.com/developer...
根据此文
instaceof可以用下列代码模拟
function instance_of(L, R) {//L 表示左表达式,R 表示右表达式
var O = R.prototype;// 取 R 的显示原型
L = L.__proto__;// 取 L 的隐式原型
while (true) {
if (L === null)
return false;
if (O === L)// 这里重点:当 O 严格等于 L 时,返回 true
return true;
L = L.__proto__;
}
}
但是
var a=1;
instance_of(a,Object)为true
a instanceof Object却返回false,这是为什么?
楼主,你可以试一试 你的
instance_of
是代替不了instanceof
的首先,明确你的样本 a 是Number 类型
但是,执行结果如下
instance_of(a, Object) // true
instance_of(a, Number) // true
修改 instance_of 方法:
再次实验: