![](/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.