JavaScript in modern browsers includes the Array.forEach method that lets you write this:
[1,2,3].foreach(function(num){ alert(num); }); // alerts 1, then 2, then 3
For browsers that don't have Array.forEach on the Array prototype, MDC provides an implementation that does the same thing:
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(fun /*, thisp*/) {
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}
Why does this implementation use /* and */ in the function definition? I.e. why is it written function(fun /*, thisp*/)
instead of function(fun, thisp)
?