The catch you fall into is that you assume that the instanceof operator is transitive. You write
ins <-- myFunction <-- Function <-- Object
and conclude that it is also true that
ins <-- Function
True that
myFunction <-- Object
but this is not related to a transitive instance.
In fact, the rule for instanceof is that if a instanceof b and b.prototype instanceof c follows that a instanceof c , but it is not required that b instanceof c . Take a look at this example:
function func() {} function superFunc() {} func.prototype = new superFunc(); var x = new func();
Now x is an instance of func and superFunc , but func not an instance of superFunc . In other languages, you better say func is a subclass of superFunc .
source share