![](/img/trans.png)
[英]What's the correct syntax for a named arrow function registered as callback?
[英]What is the correct function callback syntax?
在JavaScript中,當函數具有至少一個參數時,如何使用回調將對調用的調用編寫為函數?
使用回調時,以下是我的理解:
var result = foo();
變成
foo(function(result) {
// code that depends on 'result'
});
但是,如果foo
使用參數,應該如何編寫對foo
的調用?
是否遵循以下內容:
var result = foo(testdata);
變成
foo(function(result), testdata {
// code that depends on 'result'
});
要么
foo(function(result, testdata){
// code that depends on 'result'
});
我不確定語法是否正確。 有人可以為我提供資源或使用正確的語法幫助我嗎?
將它們作為2個不同的參數傳遞給
foo(testdata, function(result){
//do things with result
});
那么foo被定義為
function foo(testdata, callback){
//call callback when result is ready
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.