Created
November 2, 2011 07:56
-
-
Save azproduction/1333135 to your computer and use it in GitHub Desktop.
Callback chain killer [prototype]
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
var doit = new Do(); | |
function doSmth(cb) { | |
cb(null, {}); | |
} | |
function doSmth2(cb) { | |
doit.result; // Тут все ответы | |
doit.previousResult; // Тут ответ предыдущей функции | |
cb(null, {}); | |
} | |
function handleError(err){ | |
console.log('pewpew', err); return true; /*return true to continue chain*/ | |
} | |
var resultArray = doit(doSmth) | |
.doTry() | |
.then(doSmth, this) // this - context | |
.then(doSmth) | |
.doCatch(handleError) | |
.then(doSmth,doSmth,doSmth) | |
.then(function(){console.log(doit.result)}); | |
// w/ then and try catch - elegant code ^^ | |
var resultArray = doit(doSmth)(doSmth, this)(doSmth2)(doSmth,doSmth,doSmth)(function(){console.log(doit.result)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment