【发布时间】:2016-08-30 16:29:54
【问题描述】:
function foo1(a,b){
console.log(arguments); //["oldValue","oldValue"]
var newArguments = foo2.apply(this,arguments);
for (var i=0;i<arguments.length;i++){
arguments[i] = newArguments[i];
}
console.log(arguments); //["newValue","newValue"]
}
function foo2(){
arguments[0] = "newValue";
arguments[1] = "newValue";
console.log(arguments); //["newValue","newValue"]
return arguments;
}
foo1("oldValue","oldValue");
我想通过外部函数 foo2 更改 foo1 参数值。我通过在 foo2 中返回带有新参数的数组并将 foo1 参数替换为 foo1 中返回的数组来做到这一点。还有其他更优雅的方法吗?
【问题讨论】:
标签: javascript function arguments apply