'About 'myInstanceof' and javascript 'instanceof' differences

  • I don't know why output is difference...
  • Other situations are same
const myInstanceof  = (left, right) => {
    while (true) {
        if (typeof left.__proto__ !== 'object' || left.__proto__ === null) return false;
        if (left.__proto__ === right.prototype) return true;
        left = left.__proto__;
    }
}

let demo = Object.create(null);
demo.__proto__ = Object.prototype;
console.log("@", demo instanceof Object); // false
console.log("#",myInstanceof(demo, Object)); // true



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source