In MDC there are plenty of code snippets that meant to implement support for new ECMAScript standards in browsers that don't support them, such as the Array.prototype.map
function:
if (!Array.prototype.map)
{
Array.prototype.map = function(fun /*, thisp */)
{
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in t)
res[i] = fun.call(thisp, t[i], i, t);
}
return res;
};
}
What's the benefit (if there's any) of using this function rather than
function(fun, thisp)
{
// same code, just without the "var thisp = arguments[1];" line:
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var res = new Array(len);
for (var i = 0; i < len; i++)
{
if (i in t)
res[i] = fun.call(thisp, t[i], i, t);
}
return res;
}
, var t = Object(this);
rather than var t = this;
and var len = t.length >>> 0;
rather than var len = t.length;
?