How come Object.prototype.toString === toString? If I have this in the global scope:
var toStringValue = toString.call("foobaz");
I would expect toStringValue to be the value of window.toString because window is the default scope, right? How come toString by itself resolves to Object.prototype.toString instead of window.toString?
The results you’ll get will be dependent on the host environment. If I run this:
…on Chrome I get
trueandfalse, respectively; on Firefox I getfalseandfalse. IE givestrueandfalsebut see below.The window object on browsers is a bit tricky, because it’s a host object, and host objects can do strange things if they want to. 🙂 For instance, your
toString.call("foobaz")will fail on IE, because thetoStringofwindowis not a real JavaScript function and doesn’t havecallorapply. (I’m not saying it’s right to be that way, you understand…)