我需要多次調用相同的回調函數,所以我不想重複它,但它需要一個響應,除非我明確定義它,否則調用函數無法使用此響應。基本上這就是我:如何將返回響應的預定義javascript回調傳遞給作爲參數的函數?
// The callback function
function foo(response){
//do something with the response here
}
// The calling function
mainActivity(data, function(response){
// Upon receiving the data in the form of 'response', do foo to it
foo(response);
});
我會非常喜歡做的事是:
mainActivity(data, foo(response)}
但我似乎無法弄清楚如何。
你嘗試過'mainActivity(data,foo)'(傳遞它沒有調用)? – Bergi