Why is the second parameter of the function in the comment block? just curious

I found this code, and I do not understand the purpose of the comment block in the parameters:

if (!Array.prototype.some)
{
  Array.prototype.some = function(fun /*, thisp*/)
  {
    var len = this.length;
    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))
        return true;
    }

    return false;
  };
}

In my opinion, this could be a normal second parameter, and this line could be deleted:

var thisp = arguments[1];
+3
source share
3 answers

The implementation Array.prototype.somebuilt into Firefox has arity 1, i.e. accepts one argument. To implement the second optional argument without changing arity, the replacement code accesses the second argument instead through arguments[1].

I really don't know what the EcmaScript spec has to say about arity Array.prototype.some.

0
source

Array.prototype.some, , thisp, , , .

, , thisp. .

+1

, , 1. arguments expensive 2. , undefined . , . , , . MDN - , , , - .

0

All Articles