Implementation Of instanceOf function in JavaScript
javascript
Solution
You're missing the statement `object = object.__proto__;` at the bottom of the `while` loop... This traverses the prototype-chain. The `object` variable contains the current object from that chain for each step of the traversal.
Problem
Hello people of Stackoverflow! I have been going through the Mozilla Developer Network's JavaScript Guide and came across this function on the Details of the object model page: The function is to check if an object is an instance of an object constructor: ``` function instanceOf(object, constructor) { while (object != null) { if (object == constructor.prototype) return true; if (typeof object == 'xml') { return constructor.prototype == XML.prototype; } object = object.__proto__; } return false; } ``` My question is that, from the same page it says that is `chris` is an object of type `Engineer` then the following code returns true: ``` chris.__proto__ == Engineer.prototype; ``` However, in the above `instanceOf` function, it uses the following comparison expression to check if an object is an instance of a constructor function: ``` object == constructor.prototype ``` Should the expression not be: ``` object.__proto__ == constructor.prototype ``` Or am I missing a point here? Thank you all for your help and time in advance!