underscore icon indicating copy to clipboard operation
underscore copied to clipboard

Native Array.isArray works incorrectly in FF 10

Open emilisto opened this issue 14 years ago • 3 comments

I'm working on a project where we call XMLHttpRequest in an iframe to get JSON data to populate Backbone models without violating the cross origin policy. The problem is when we later try to use _.isArray on this JSON data (or more correctly on the object, created from the JSON data in the iframe, from outside the iframe), but in Firefox 10 this triggers a bug with native the Array.isArray wrongly returning false.

See this gist for a clear demonstration: https://gist.github.com/1721221

I assume this is a not to uncommon approach, so unless a workaround is introduced in underscore, many users will be affected by this until the next Firefox update is out. It has been addressed and resolved in the nightly FF build.

https://bugzilla.mozilla.org/show_bug.cgi?id=723388

emilisto avatar Feb 14 '12 09:02 emilisto

see also http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/#dean_edwards_solution

yuchi avatar Feb 14 '12 09:02 yuchi

Ugh, but I think that if isArray exists, we should trust it.

If Firefox 10 were going to be around like IE6 for decades, then we should add a workaround ... but since everyone will be auto-upgraded off of it in short order, I think it's best to leave this be.

jashkenas avatar Feb 14 '12 15:02 jashkenas

You're right. Here's a snippet to replace isArray for FF10 users meanwhile, so you don't need to vacuum your code because of this.

https://gist.github.com/1834061

ghost avatar Feb 15 '12 07:02 ghost