为什么toString()和this.toString()在Chrome的控制台中产生不同的结果? [英] Why do toString() and this.toString() produce different results in Chrome's console?
问题描述
现在这根本没有任何实际意义,但是我对偶然发现的这个小怪癖感到好奇.
Now this has no practical implications at all, but I am curious about this little quirk I stumbled upon.
基本上,在Chrome的开发者控制台中,此
Basically, in Chrome's developer console, this
toString()
返回[object Object]
,而此
this.toString()
返回[object DOMWindow]
.
据我所知,这仅是在控制台上发生的,可以在此jsFiddle上的 看到 . ## javascript上的某人发现
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.
那么为什么toString()
和this.toString()
在Chrome的控制台中产生不同的结果?
So why do toString()
and this.toString()
produce different results in Chrome's console?
推荐答案
WebKit恰好在控制台中对全局调用使用了错误的上下文.
WebKit happened to use wrong context for global calls in the console.
(Chrome 14):
(Chrome 14):
> this
DOMWindow
> this.toString()
"[object DOMWindow]"
> toString()
"[object Object]"
> valueOf()
CommandLineAPI
我认为此问题已通过此处
这篇关于为什么toString()和this.toString()在Chrome的控制台中产生不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!