Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That way is longer without reason, you must first define in the function scope both variables error and result; the latter only receives assignation when no error has been generated.

    function doAsyncCall(callback){
        var error, result;
        // .. do some async stuff
        // assign error if there was one or result when everything went fine
        if( !error ){ result = data; }
        callback(error, result);
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: