1

他のすべてのビルトインは、グローバル オブジェクトにアタッチされます。

> 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、しかし、そうではありません:

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

アクセスする方法はありますか?

4

1 に答える 1

2

のインスタンスを手動で作成したいということであればArguments、それは不可能です。Argumentsコンストラクタ関数はありません。

そのタイプのオブジェクトは、実際には内部アルゴリズムによって作成されます ( ECMAScript 仕様のセクション 10.6を参照)。の出力として表示されるのは、オブジェクトObject.prototype.toString.callの内部プロパティに格納されている値です。[[Class]]それは何でもかまいません。この場合、仕様では、文字列「Arguments」に設定する必要があると定義されています。

于 2013-03-27T21:10:25.033 に答える