我有一个名为history
的javascript对象。在测试我的应用程序时,在 chrome 上得到完全不可预测的结果。
在 Firefox 上,我的应用程序运行良好:当我 console.log(history)
获取以下屏幕时
但在 Chrome 上受到关注
当我第一次看到这个屏幕时,我想也许 Chrome 添加了一些其他细节,例如长度和状态。但事实上,当我在 chrome 上迭代对象(如下面的示例)时,它首先打印出 state
并将值设置为 null。
$.each(history, function (hash,files) { ...
有趣的是,相同的代码在 Firefox 上运行起来就像一个魅力。
我做错了什么?
最佳答案
您不应定义名为 history
的变量,因为它已经是 Web API 接口(interface)的一部分,
which provides an interface for manipulating the browser session history (pages visited in the tab or frame that the current page is loaded in) - Window.history (Web API Interfaces | MDN)
它包含在window
对象下,因此它是网页中的全局变量。您无法覆盖它,但这取决于浏览器,哪个浏览器优先于另一个。
关于javascript - Google Chrome 上的结果不可预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25068936/