在函数代码中,使用特殊对象 arguments,开发者无需明确指出参数名,就能访问它们。 arguments.length可以拿到当前函数传递过来的所有参数长度。arguments.callee 可以查看当前函数。 arguments[i] 可以查看指定索引的参数。
function func(a,b,c){
console.log(a+b+c);
console.log(arguments.length);
console.log(arguments[0]);
console.log(arguments[1]);
console.log(arguments[2]);
}
func("hello","world","hehe");
- 打印结果:
helloworldhehe
3
hello
world
hehe