Created
September 7, 2012 14:37
-
-
Save pifantastic/3666728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method one, return statement after callback. | |
// Most clear, but extra line of code. | |
function asyncBiznis (callback) { | |
moreAsyncBiznis(function (err, result) { | |
if (err) { | |
callback( new Error("Hope is lost.") ); | |
return; | |
} | |
// More logic... | |
}); | |
}); | |
// Method two, return on callback. | |
// Less clear, but saves a line of code. | |
function asyncBiznis (callback) { | |
moreAsyncBiznis(function (err, result) { | |
if (err) { | |
return callback( new Error("Hope is lost.") ); | |
} | |
// More logic... | |
}); | |
}); | |
// Method three, wrap all other logic in else{} | |
// Also clear, but results in extra indentation. | |
function asyncBiznis (callback) { | |
moreAsyncBiznis(function (err, result) { | |
if (err) { | |
callback( new Error("Hope is lost.") ); | |
} | |
else { | |
// More logic... | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment