📜  响应 node.js 中的回调 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:08.128000             🧑  作者: Mango

代码示例1
//you can only return a value from an async function by passing in a callback function like so: 
function longRunningFunction(param1, callback){
    setTimeout(function(){
         var results="O High there!";
         callback(results);
    }, 2000);
} 

//then call the async function and pass the callback function like so
longRunningFunction("morning", function(result){
  alert(result);
});