gpt4 book ai didi

jquery - $.isPlainObject($ ('...' )) == true 在 IE 中

转载 作者:行者123 更新时间:2023-12-01 00:08:58 24 4
gpt4 key购买 nike

FF/Chrome 中没有,我认为 IE 中也不应该有。毕竟 $() 不返回普通对象,而是返回 $ 的实例。我错了吗?

最佳答案

简短回答: 不,你没有疯,这确实是 jQuery 核心中的一个错误。

<小时/>

长答案:

我设置了一个快速测试来看看这里有什么区别:http://jsfiddle.net/nick_craver/9J3VP/

属性列表在 IE 中的顺序不同(至少 8 个),因此这部分 ( from jQuery core ):

var key;
for ( key in obj ) { }

它获取列表中的最后一个属性并对其进行 hasOwnProperty 检查,因此在 IE 中可以归结为以下内容:

Object.prototype.hasOwnProperty.call($(document.body), 'length') //true

在其他浏览器中(已测试 FF/Chrome):

Object.prototype.hasOwnProperty.call($(document.body), 'width') //false

由于属性列表的顺序不同,它在 IE 中获取 length 属性,而在其他浏览器中则获取 else 属性,因此我们得到了不同的结果(对于踢,单击以在左侧包含 jQuery UI,观察它更改为另一个自定义属性,tabs)。 This comment above the for loop :

// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.

这是关于 IE 属性排序的错误假设,因此我认为这是 jQuery 1.4.2 中的一个错误。

关于jquery - $.isPlainObject($ ('...' )) == true 在 IE 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3399649/

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