$ .isPlainObject($('...'))==在IE中为true [英] $.isPlainObject($('...')) == true in IE
问题描述
它不在FF/Chrome中,而且我不认为它在IE中.毕竟$()不会返回普通对象,而是$的实例.我错了吗?
It doesn't in FF/Chrome and I don't think it should in IE. after all $() doesn't return a plain object, but an instance of $. Am I wrong?
推荐答案
简短回答: 不,你并不疯狂,这确实是jQuery核心中的错误
Short Answer: no, you're not crazy, it is indeed a bug in jQuery core.
长答案:
我设置了一个快速测试以查看此处的区别: http://jsfiddle.net/nick_craver/9J3VP/
I setup a quick test to see what the difference is here: http://jsfiddle.net/nick_craver/9J3VP/
属性列表在IE中的顺序有所不同(至少为8),因此这部分(来自jQuery核心):
The property list differs in it's order in IE (8 at least), so this part (from jQuery core):
var key;
for ( key in obj ) { }
它获取列表中的最后一个属性,并对其进行hasOwnProperty
检查,因此它在IE中沸腾到这一点:
It grabbing the last property in the list and doing a hasOwnProperty
check on it, so it's boiling down to this in IE:
Object.prototype.hasOwnProperty.call($(document.body), 'length') //true
,并在其他浏览器中(经过FF/Chrome测试):
and this in other browsers (tested FF/Chrome):
Object.prototype.hasOwnProperty.call($(document.body), 'width') //false
由于属性列表的排序方式不同,因此它在IE中捕获了length
属性,而在其他浏览器中则是 else ,因此我们得到了不同的结果(对于踢,单击以包含jQuery在左侧的用户界面中,观看它是否更改为另一个自定义属性tabs
). 在for
循环上方的评论:>
Since that property list is ordered differently, it's grabbing the length
property in IE, and something else in other browsers, we're getting a different result (for kicks, click to include jQuery UI on the left, watch it change to another custom property, 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开始,我认为这是一个错误.
Is a false assumption about IE's property ordering, so I'd consider this a bug as of jQuery 1.4.2.
这篇关于$ .isPlainObject($('...'))==在IE中为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!