function fiboCoffee(L,R){
var O = R.prototype;
let fibo = { [Symbol.iterator](){
return{
next(){
L = L.__proto__;
return {done:false,value:L};
}
}
}
}
for(n of fibo){
if(n === O){
return true;
}
else if(n === null){
return false;
}
}
};
for...of
的初始值是执行第一遍next
的返回值,所以在初始化L
时,要注意应该在next
函数里初始化,否则判断就会出现错误。
使用
function A(){};
function b(){};
var a = new A();
var b = new B();
fiboCoffee(b,A); // false;
fiboCoffee(a,A); // true;
b.__proto__ = A.prototype;
fiboCoffee(b,A); // true;
a instanceof A; // true