2

MDN says it is "an Array like object" but does not say what it is an instance of.

It is not an HTMLCollection or NodeList.

If I call Object.prototype.toString.call(arguments) it returns "[object Arguments]" but arguments instanceof Arguments is an error.

So what is arguments an instance of?

0

2 Answers 2

8

So what is arguments an instance of?

It's an instance of Object. There does not appear to be any public Arguments constructor that you can use with instanceof to identify it that way.

If you want to uniquely identify it, then:

Object.prototype.toString.call(arguments) === "[object Arguments]"

is a safe way to identify it.

Per section 9.4.4 in the EcmaScript 6 specification, the arguments object is either an ordinary object or an exotic object. Here's what the spec says:

Most ECMAScript functions make an arguments objects available to their code. Depending upon the characteristics of the function definition, its argument object is either an ordinary object or an arguments exotic object.

An arguments exotic object is an exotic object whose array index properties map to the formal parameters bindings of an invocation of its associated ECMAScript function.

Arguments exotic objects have the same internal slots as ordinary objects. They also have a [[ParameterMap]] internal slot. Ordinary arguments objects also have a [[ParameterMap]] internal slot whose value is always undefined. For ordinary argument objects the [[ParameterMap]] internal slot is only used by Object.prototype.toString (19.1.3.6) to identify them as such.

Since it is an "exotic" object, that essentially means it doesn't follow all the normal and expected conventions. For example, there is no constructor function from which you can create your own object. And, because there is no public constructor function, that probably also explains why there's no instanceof that you can test on it to uniquely identify it.

0

You can retrieve the name of the function where arguments returned from using callee.name

function test() {
  this.args = arguments;
}

var obj = new test();

console.log(obj.args.callee.name);

function test() {
  return arguments
}

console.log(test().callee.name);

See also Why was the arguments.callee.caller property deprecated in JavaScript? , Arguments object

2
  • 2
    Can't do this in strict mode.
    – jfriend00
    Commented Apr 16, 2016 at 3:38
  • @jfriend00 Yes; included link to more details. Commented Apr 16, 2016 at 3:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.