Here’s some strange javascript behavior of the map function in Firefox.
During an error condition of a web-app (when firebug pauses on the error) typing the following into Firebug console:
["a", "b", "c", "d"].map(function(val, i, arr) {
return val + " " + i + " " + typeof arr;
});
produces the following un-expected result:
["a undefined undefined",
"b undefined undefined",
"c undefined undefined",
"d undefined undefined"]
At that time, if I open up another blank tab and type the same statement into the blank tab’s Firebug Console, it produces the following expected result:
["a 0 object",
"b 1 object",
"c 2 object",
"d 3 object"]
This means, in the error condition, map calls the callback with 1 argument instead of the expected 3 arguments.
Quote from MDN:
(https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map)
callback is invoked with three arguments: the value of the element,
the index of the element, and the Array object being traversed.
Is the unexpected behavior because of the app forcing firefox into some mode?
(I’m using Firefox 12.0)
It sounds like some other code in your application might be overwriting the Array.prototype.map function — an incompletely implemented polyfill, perhaps? If you type
[].mapinto the console, and if it doesn’t sayfunction map() { [native code] }then this is almost certainly the case.