Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:58:24+00:00 2026-05-27T07:58:24+00:00

When working on my latest web application and needing to use the Array.forEach function,

  • 0

When working on my latest web application and needing to use the Array.forEach function, I constantly found the following code used to add support to older browsers that do not have the function built in.

/**
 * Copyright (c) Mozilla Foundation http://www.mozilla.org/
 * This code is available under the terms of the MIT License
 */
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 it copied with the formal thisp parameter commented out and having it be set as a local variable using arguments[1] instead.

I was wondering if anyone knew why this change was made, because from what I can tell, the code would have worked fine with thisp as a formal parameter rather than a variable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:58:25+00:00Added an answer on May 27, 2026 at 7:58 am

    Array.prototype.forEach.length is defined as 1, so implementation functions would be more native-like if they had their .length property set to 1 too.

    http://es5.github.com/#x15.4.4.18

    The length property of the forEach method is 1.

    (func.length is the amount of argument that func takes based on its definition.)

    For func.length to be 1, you have to define func to only take 1 argument. In the function itself you can always get all arguments with arguments. However, by defining the function to take 1 argument, the .length property is 1. Therefore, it is more correct according to the specification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When working with my .Net 2.0 code base ReSharper continually recommends applying the latest
I upgraded a large ASP.NET MVC application I've been working on to the latest
We are working on a web application that is distributed across 3 load-balanced web
I'm trying to get client validation working on my asp.net mvc 2 web application
We are working on a 3-tier application, and we've been allowed to use the
I have a web application on java, which is working with database. I need
I'm working with a friend on a web application we'd like to distribute and
The following code will not run correctly in IE7 with the latest service packs
A project I'm working on requires the use of jQuery on customers' Web pages.
Currently, I have a ASP.net 3.5 web application for which I currently am working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.