Created
May 12, 2017 04:05
-
-
Save jcyh0120/75a3dd0a3997c159042dbf976816e725 to your computer and use it in GitHub Desktop.
Example Promise
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 result = FunA(test) | |
.then(function(){ | |
return FunB(); | |
}).catch(function(error){ | |
//handle error here??? | |
console.error(error); | |
}); | |
function FunA(test){ | |
return new Promise(function(resolve,reject){ | |
if(test){ | |
resolve(test); | |
} else { | |
reject(test); | |
} | |
}) | |
} | |
function FunB(){ | |
return FunOther().then(function(result){ | |
return result; | |
}).catch(function(err){ | |
//handle error here??? | |
console.error(err); | |
}) | |
} | |
function FunOther(other){ | |
return new Promise(function(resolve,reject){ | |
if(other){ | |
resolve(other); | |
} else { | |
reject(other); | |
} | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment