https://bugzilla.wikimedia.org/show_bug.cgi?id=20376
Summary: Replace "for ... in" loop with proper iteration over
index array
Product: MediaWiki
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: Normal
Component: General/Unknown
AssignedTo: [email protected]
ReportedBy: [email protected]
In the JavaScript file wikibits.js there is an iteration over an indexed array
using a "for ... in" style loop. This style of loops works on arrays when they
are only being used as arrays and have not been extended in anyway. However,
while this does work, it is not the proper use of the "for ... in" style loop.
This iterative loops is design for stepping through all of the properties of an
object. Since an array is an Object, it can contain properties other than the
simple indexes. When you only want to step through the numbered indexes of an
array, you should use the "for (var x = 0; x < array.length; x++)" loop.
The only reason this comes up is that in some of the extensions we've written
for our wikis we make use of prototype.js (which is known to extend all
objects, including arrays) ... which in turn causes a JavaScript error
ta[id][0] is undefined.
While neither party is in the right here, and debates can, have and likely will
be held on which is more wrong, I offer you this simple solution to fix your
own end, so that you may be more righteous and zealous in any arguments you may
have against prototype.
In the core code of 1.13.2 (unsure of where it may lie in other releases)
wikibits.js approx. line 338 the current code reads:
for (var id in ta) {
If you change it to read:
for(var id = 0 ; id < ta.length ; id++) {
Everything will still work as it has in the past, but it will not throw errors
at those extending the array object either.
your attention to this matter is appreciated, even if you end up scoffing at us
and not fixing it.
--
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l