Hareeshchandera / jsplumb

Automatically exported from code.google.com/p/jsplumb
0 stars 0 forks source link

Extended Array in 1.3.4 #159

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I connected jsPlumb-1.3.4-RC1.js to our application.

We use some jquery plugins. There are errors in plugins.

After investigation we found the problem:

// for those browsers that dont have it, Array.find using a function.
Array.prototype.find = Array.prototype.find || function(f) {
    for(var i = 0; i < this.length; i++) if (f(this[i])) return i;
        return -1;
};

What to do?
It will be fixed in jsPlumb?

Original issue reported on code.google.com by taras...@gmail.com on 28 Dec 2011 at 10:42

GoogleCodeExporter commented 8 years ago
the code is written to not overwrite the find function on Array if it already 
exists.  but you have found that it does overwrite Array.prototype.find?  what 
other plugins do you use?  can you provide a test page on jsfiddle?

Original comment by simon.po...@gmail.com on 28 Dec 2011 at 11:02

GoogleCodeExporter commented 8 years ago
I think it all depends on the type of loop.

http://jsfiddle.net/cHdyd/

When we use this type, we expect one and receive different.

What will be the best solution?

Original comment by taras...@gmail.com on 28 Dec 2011 at 4:04

GoogleCodeExporter commented 8 years ago
cool, thanks - i've changed the function to be internal to jsPlumb.

it's not actually a bug, incidentally - "for-in" is designed to iterate through 
the members of some object, not just the indexed members, and is slower than 
using the (for var i = 0; i < array.length; ....) syntax.  a good defensive 
coding practice is to avoid for-in for arrays and only use it for objects whose 
properties you want to iterate (IE can trip you up here).

there are quite a few discussions on this topic on StackOverflow, for example:

http://stackoverflow.com/questions/500504/javascript-for-in-with-arrays

..but like i said, i changed it, since i want jsPlumb to be as unobtrusive as 
possible.

Original comment by simon.po...@gmail.com on 28 Dec 2011 at 9:05

GoogleCodeExporter commented 8 years ago

Original comment by simon.po...@gmail.com on 28 Dec 2011 at 9:05

GoogleCodeExporter commented 8 years ago
Thanks

Original comment by taras...@gmail.com on 30 Dec 2011 at 9:50

GoogleCodeExporter commented 8 years ago
1.3.4 was released today.

Original comment by simon.po...@gmail.com on 9 Jan 2012 at 6:59