2016-08-08 126 views
0

我有 'FUNC1' 它包裝異步 'FUNC2',如:如何爲異步函數創建異步包裝函數?

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

如何使 'FUNC1' 異步太(外部代碼)。

回答

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) }