Now this has no practical implications at all, but I am curious about this little quirk I stumbled upon.
Basically, in Chrome's developer console, this
toString()
returns [object Object]
, whereas this
this.toString()
returns [object DOMWindow]
.
As far as I know, this only happens from the console, as can be seen on this jsFiddle. Someone on ##javascript found this link explaining where the function comes from. However, it doesn't explain the discrepancy there is in the behavior when used within or outside the console.
So why do toString()
and this.toString()
produce different results in Chrome's console?
The toString() method returns a string representing the source code of the specified Function .
Parameters Used: This method accepts a single optional parameter base. This parameter specifies the base in which the integer is represented in the string. It is an integer between 2 and 36 which is used to specify the base for representing numeric values.
Using toString() to detect object classtoString() can be used with every object and (by default) allows you to get its class.
WebKit happened to use wrong context for global calls in the console.
(Chrome 14):
> this
DOMWindow
> this.toString()
"[object DOMWindow]"
> toString()
"[object Object]"
> valueOf()
CommandLineAPI
I think this has been fixed over here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With