如何为异步函数制作异步包装函数?

时间:2016-08-08 13:34:14

标签: javascript asynchronous

我有' func1'包裹异步' func2'喜欢:

func1 = function(arg1) {
    func2 (arg1, function(result) {
       // parse and return some parts of 'result'
    }, function(error) {
       alert (error.message);
    })
}

如何制作' func1'也是异步(对于外部代码)。

1 个答案:

答案 0 :(得分:1)

function wrapper(callback) {//async callback is the standard for most libs func1(arg1);//call that original func1 you defined. callback(); //first arg is error, second is result (you don't have any result so it is empty) }