Javascript 为什么函数参数不能通过function.apply()递归传递?
我试图在完成后将ajax调用链接到web服务。这些是从Javascript 为什么函数参数不能通过function.apply()递归传递?,javascript,Javascript,我试图在完成后将ajax调用链接到web服务。这些是从input type=file保存文件的大量调用 //Here's where I chain the requests (example simplified for readability) saveData(arg1, saveData, [arg1, saveData, [arg1, ....); //Here's my function definition (example simplified for
input type=file
保存文件的大量调用
//Here's where I chain the requests (example simplified for readability)
saveData(arg1,
saveData, [arg1,
saveData, [arg1, ....);
//Here's my function definition (example simplified for readability)
function saveData(arg1, callBack, callBackArgs) {
$.ajax({ //Breakpoint 2. placed here shows all parameters -
//arg1, callBack and callBackArgs to be null! What gives?
type: "POST",
url: '@Url.Action("MyAction", "MyController")',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
async: true,
success: function (result) {
callBack.apply(callBackArgs); //Breakpoint 1. placed here shows callback
//and callBackArgs to be set perfectly fine
},
error: function (error) {
console.log(error);
}
});
}
我错过了什么?为什么function.apply()
不能递归工作?有没有其他方法可以实现这一点?函数的.apply()
采用两个参数:
callback.apply(undefined, callBackArgs);
这假设您不需要将
this
绑定到任何对象。方法.apply()
包含两个参数:第一个是所需的this
值,第二个是参数数组。谢谢!你能不能把你的评论作为一个答案发表出来,这样我就可以结束这篇文章了?