gpt4 book ai didi

javascript - 为什么 `toString` 不等于 `window.toString` ?

转载 作者:数据小太阳 更新时间:2023-10-29 05:19:30 25 4
gpt4 key购买 nike

我相信所有全局变量都可以从全局对象访问。因此,如果我可以访问 x(并且 x 未在本地绑定(bind)),则 window.x 是相同的值。

但是,在网页中 ( on JSFiddle ):

window === this // true in Chrome and Firefox
toString === window.toString // true in Chrome and Firefox

但是在控制台中:

window === this // true in Chrome console and Firebug, false in Firefox web console
toString === window.toString // false in Chrome, Firebug and Firefox web console

这是为什么?为什么 window 是 Chrome 控制台中的全局对象,而 toString 没有绑定(bind)到 window.toString? Firefox 控制台中绑定(bind)的 toString 是什么?控制台中还有哪些其他全局值不同?

最佳答案

toString 不是全局变量。这是几乎所有对象共享的方法,包括 window 对象。

始终window 对象上可用的实际全局变量。

关于javascript - 为什么 `toString` 不等于 `window.toString` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14160211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com