Unexpected "arguments" property on object

In the following, the second and third outputs of the console seem to contradict:

function test() { console.log(arguments); // -> ["my", "arguments"] console.dir(this); // -> test function with arguments property set to null console.log(this.arguments); // -> ["my", "arguments"] } test.call(test, 'my', 'arguments'); 

According to my comments, checking the arguments property for this shows null , while logging this.arguments clearly shows ["my", "arguments"] .

What is this when you call a function this way? I did not expect this.arguments to contain call arguments!

+6
source share
2 answers

MDN says

arguments , since the Function property can no longer be used.

Therefore, I would not even try to use this.arguments , but use the local function variable arguments . Clearly, there is another magic to creating arguments .

+5
source

What exactly happens when a function is called this way? I did not expect this.arguments to contain call arguments!

this keyword really refers to the test function - what you call ed with. You can argue that by registering this === test .

So what is this arguments property? A very deprecated one that is installed on the actual arguments object during a function call (and subsequently deleted, which, apparently, is the reason that console.dir did not commit it correctly). Do not use it and do not care about it :-)

 function test() { console.assert(this === test); console.assert(this.arguments === arguments); console.log(Object.getOwnPropertyDescriptor(this, "arguments")); } test.call(test, 'my', 'arguments'); // result (in Opera): Object { configurable: false, enumerable: false, value: Arguments { 0: "my", 1: "arguments", callee: Function {…}, length: 2 }, writable: false } 
+5
source

All Articles