When working with my latest web application and using the Array.forEach
function Array.forEach
I constantly found the following code used to add support for older browsers that do not have a built-in function.
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); } } }; }
I fully understand what the code does and how it works, but I always see that it is copied with the formal thisp
parameter, commented out and setting it as a local variable instead of arguments[1]
.
I was wondering if anyone knows why this change was made, because from what I can say, the code would work fine with thisp
as a formal parameter and not a variable?
source share