function MyInstanceof(left, right){
if(left === null || typeof left !== 'object'){
return false
}
if(left.__proto__ === right.prototype){
return true
}
return MyInstanceof(left.__proto__, right)
}
function Foo() {}
let f = new Foo();
console.log(MyInstanceof(f, Foo)); // true
console.log(MyInstanceof(f, Object)); // true
function Bar() {}
function Baz() {}
Baz.prototype = new Bar();
let b = new Baz();
console.log(MyInstanceof(b, Bar)); // true
console.log(MyInstanceof(b, Baz)); // true