Here's an interesting observation regarding the behavior of the map
function in Firefox.
In a particular error scenario on a web application, when Firebug pauses at the error, entering the following code into the Firebug console:
["a", "b", "c", "d"].map(function(val, i, arr) {
return val + " " + i + " " + typeof arr;
});
results in an unexpected output:
["a undefined undefined",
"b undefined undefined",
"c undefined undefined",
"d undefined undefined"]
Interestingly, if the same code is executed in the Firebug console of a new blank tab during the error condition, it produces the expected output:
["a 0 object",
"b 1 object",
"c 2 object",
"d 3 object"]
This discrepancy suggests that in the error scenario, the map
function only calls the callback with one argument instead of the expected three arguments.
The official documentation by MDN states: (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map)
The callback should be invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
This raises the question of whether this unexpected behavior is triggered by the app forcing Firefox into a specific mode?
(Tested on Firefox 12.0)