Stylish-Select icon indicating copy to clipboard operation
Stylish-Select copied to clipboard

Array.prototype.indexOf causes for..in on Array to have extra element in IE

Open zajax opened this issue 13 years ago • 3 comments

I came across this the other day. Another developer was using for...in to loop through an Array. In IE, it would include the indexOf function as an item in the area. Very odd, but a pain to figure out.

Recreate: Include stylish select.

In another javascript file, after stylish select has been run, execute this code:

var arr = [1,2,3];

for(var i in arr){ alert(arr[i]); alert(typeof(arr[i])); }

Question: Do you need to add indexOf to the prototype, or could you just use the $.inArrray()? http://api.jquery.com/jQuery.inArray/

zajax avatar Jun 24 '11 15:06 zajax

Any updates on this. I can submit a fix?

Or is this project pretty dead?

ifiokjr avatar Dec 16 '14 17:12 ifiokjr

Not touched the project for a while, but you're welcome to submit a pr if you like.

On 16 December 2014 at 17:06, Ifiok Jr. [email protected] wrote:

Any updates on this. I can submit a fix?

Or is this project pretty dead?

Reply to this email directly or view it on GitHub https://github.com/scottdarby/Stylish-Select/issues/28#issuecomment-67193706 .

scottdarby avatar Dec 16 '14 17:12 scottdarby

Also it's worth noting that that the indexOf prototype override in this plugin can dramatically affect other code. I had a problem today when some third-party JS (a widget) was relying on indexOf returning -1 when it can't find a given element in the array - the expected response.

However, this module (crazily) returns undefined, completely borking the expected behaviour and resulting in broken widgets everywhere. Discontinued!

simonhamp avatar Oct 11 '16 23:10 simonhamp