Arguments object typecasting

Viewed 90

Kindly I am a beginner in JavaScript world, and I have a question with the below simple example,

function myFun(){
    return arguments;
}

var myVar=myFun("a","b","c"); 

//1
console.log(myVar); //=>//["a", "b", "c", callee: function, Symbol(Symbol.iterator): function]

//2
for(m in myVar){
    console.log(m); //will generate only the realistic arguments "a","b","c".
}

According to the above snippet, why should the first invoking generate the arguments object with the inherited properties from the Function main object, and the second will generate only the realistic arguments.

If we passed the arguments object to a second function, why should it will be passed with the realistic data only, for example

function foo(something) {
console.log(something); ///=>this will generate number 3 as parameter only, not the rest of the object
 return this.a + something;
}
var obj = {
 a: 2
};
var bar = function() {
 return foo.apply( obj, arguments );
};
var b = bar( 3 ); // 2 3

as pointed in the line of console.log(something), it will generate only the realistic params only

2 Answers
Related