davidchambers
davidchambers

Reputation: 24806

Can one access the Arguments "class" in JavaScript?

All other built-ins are attached to the global object:

> Object.prototype.toString.call(new Date)
'[object Date]'
> new Date instanceof Date
true
> Object.prototype.toString.call(new Function)
'[object Function]'
> new Function instanceof Function
true
> Object.prototype.toString.call(new Number)
'[object Number]'
> new Number instanceof Number
true

Arguments, however, is not:

> args = null; (function() { args = arguments }()); Object.prototype.toString.call(args)
'[object Arguments]'
> new Arguments instanceof Arguments
ReferenceError: Arguments is not defined

Is there any way to access it?

Upvotes: 1

Views: 43

Answers (1)

bfavaretto
bfavaretto

Reputation: 71908

If you mean you want to manually create an instance of Arguments, then it's not possible. There is no Arguments constructor function.

Objects of that type are actually created by an internal algorithm (see section 10.6 of the ECMAScript specification). What you see as the output of Object.prototype.toString.call is just the value stored in the [[Class]] internal property of the object. It could be anything. In this case, the specification defines it should be set to the string "Arguments".

Upvotes: 2

Related Questions