why does Object._proto_ instanceof Function gives me false?
alert(Object.__proto__ ); // clearly Object.__proto__ is a function right?
alert(typeof Object.__proto__); // clearly Object.__proto__ is a function right?
alert(Object.__proto__ instanceof Function); // !
Not all functions are created via the
Functionconstructor.instanceofchecks specifically to see if the given item was created by that specific function.You get a similar effect in browser environments when dealing with multiple windows. I mean, if you have function
fooin window A:…and you have code in another window B that calls it:
…then you’d expect
footo realize thatargis an array, right? But it doesn’t, because althoughargis an array, it wasn’t created by theArrayconstructor in the window thatfoois in.More about figuring out what things are here: Say what?
If you’re fascinated by this stuff (as you seem to be), there’s nothing quite like reading the specification. Yes, the prose is…dry…and the terminology is….dense…but it gets more and more interesting as you learn more and more about the underlying workings.
Off-topic: Beware that
__proto__is non-standard and not supported by all JavaScript implementations.