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 4613974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:37:50+00:00 2026-05-22T01:37:50+00:00

In MDC there are plenty of code snippets that meant to implement support for

  • 0

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;?

  • 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-22T01:37:50+00:00Added an answer on May 22, 2026 at 1:37 am
    var len = t.length >>> 0;    
    

    This was covered pretty well in this question Basically it makes sure the number is a non-negative 32 bit int.

    As for the Object constructor:

    var t = Object(this);
    

    If this is null or undefined, it’ll return an empty object. From the MDC Docs on Object

    The Object constructor creates an
    object wrapper for the given value. If
    the value is null or undefined, it
    will create and return an empty
    object, otherwise, it will return an
    object of type that corresponds to the
    given value.

    They’re both just quick ways to do error correction.

    EDIT: I was thinking way too hard about the thisp part. I was assuming that using the arguments array was a way to ensure arguments were defaulting to undefined, but they do that on their own anyway. Mike Hofer got it right in the comments. It’s Mozilla’s coding style to indicate optional parameters. Function.call defaults to global if null or undefined is passed in as the first argument. From the MDC Docs on Function.call

    thisArg:
    Determines the value of this inside
    fun. If thisArg is null or undefined,
    this will be the global object.
    Otherwise, this will be equal to
    Object(thisArg) (which is thisArg if
    thisArg is already an object, or a
    String, Boolean, or Number if thisArg
    is a primitive value of the
    corresponding type). Therefore, it is
    always true that typeof this ==
    “object” when the function executes.

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

Sidebar

Related Questions

I don't find anything about my question here on MDC or the ECMAscript specifications.
quoting MDC : If there is a possibility that your logic could take longer
There are plenty of solutions on how to get the indexOf implementation into the
I was looking through the jQuery code and found that isArray is implemented using
JavaScript in modern browsers includes the Array.forEach method that lets you write this: [1,2,3].foreach(function(num){
On MDC's site they have a cool demo of dispatchEvent that works fine in
I have some code that uses dispatchEvent to simulate clicks and the same exact
is there a way to pause / resume for HTML5 Canvas? Say my code:
MDC says to do this, but also says that they think it's just a
Toying around with the WebKit browser in the new Kindle 3G, I noticed that

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.