我有以下功能
//simple function with parameters and variable
function thirdfunction(a,b,c,d){
console.log("the value of a is: " + a);
console.log("the value of b is: " + b);
console.log("the value of c is: " + c);
console.log("the value of d is: " + d);
console.log("the arguments for each values are: " + arguments);
console.log("the number of arguments passed are: " + arguments.length);
}
console.log("no parameter values are passed");
thirdfunction();
console.log("only a and b parameter values are passed");
thirdfunction(1,2);
但是,arguments
如果我连接文本,则不显示传入的值the arguments for each values are:
。这是为什么?
连接时我从谷歌控制台得到的输出如下;
no parameter values are passed
the value of a is: undefined
the value of b is: undefined
the value of c is: undefined
the value of d is: undefined
the arguments for each values are: [object Arguments]
the number of arguments passed are: 0
only a and b parameter values are passed
the value of a is: 1
the value of b is: 2
the value of c is: undefined
the value of d is: undefined
the arguments for each values are: [object Arguments]
the number of arguments passed are: 2
当我不连接时,会传递以下值。
no parameter values are passed
the value of a is: undefined
the value of b is: undefined
the value of c is: undefined
the value of d is: undefined
[]
the number of arguments passed are: 0
only a and b parameter values are passed
the value of a is: 1
the value of b is: 2
the value of c is: undefined
the value of d is: undefined
[1, 2]
the number of arguments passed are: 2
编辑
不知道为什么这个问题被否决了,但我遇到的问题是,当我使用该语句时console.log("the arguments for each values are: " + arguments);
,控制台中的输出是console.log("the arguments for each values are: " + arguments);
但是如果我通过该语句console.log(arguments);
,控制台中的输出是[]
or [1, 2]
?