Consider this:
var x = function() { return arguments; } console.log( x() === x() );
This is false because it is not the same arguments object: it (for each involution x ) is a new object that has the values โโof all parameters stored inside. However, it does have arguments properties:
var y = x([]); console.log(y instanceof Object); // true console.log(y instanceof Array); // false console.log(y.length); // 1 console.log(y.callee + ''); // function() { return arguments; }
And yet there is more to it. Obviously, objects sent to the function as their parameters will not be collected by the GC if arguments returned:
var z = x({some: 'value'}); console.log(z[0]);
Expected: in the end, you can get a similar result by declaring some local object inside the function, assigning the value of the first parameter of the function as a property of the object "0", and then returning this object. In both cases, the mentioned object will still be "used", so I do not assume.
But what about this?
var globalArgs; var returnArguments = function() { var localArgs = arguments; console.log('Local arguments: '); console.log(localArgs.callee.arguments); if (globalArgs) { // not the first run console.log('Global arguments inside function: '); console.log(globalArgs.callee.arguments); } return arguments; } globalArgs = returnArguments('foo'); console.log('Global arguments outside function #1: '); console.log(globalArgs.callee.arguments); globalArgs = returnArguments('bar'); console.log('Global arguments outside function #2: '); console.log(globalArgs.callee.arguments);
Output:
Local arguments: ["foo"] Global arguments outside function #1: null Local arguments: ["bar"] Global arguments inside function: ["bar"] Global arguments outside function #2: null
As you can see, if you return the arguments object and assign it to some variable, inside the function its callee.argument property points to the same data set as arguments ; this, again, was expected. But outside the function variable.callee.arguments is zero (not undefined).
raina77ow
source share