Created
February 25, 2018 10:35
-
-
Save a1exlism/c565e1904346022a7d69bd5e27867acf to your computer and use it in GitHub Desktop.
// simple calculation with promise-chain
// then 会包装成一个新的Promise对象, 并把return作为参数引入
This file contains hidden or 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
| let initNum = 10; | |
| Promise.resolve(initNum).then(function add(num) { // fulfilled function | |
| num += 10; | |
| console.log('add 10 to =>' + num); | |
| return num; | |
| }, function addRej(num) { // onReject | |
| console.log('Reject add operation.'); | |
| }).then(function devide(num) { | |
| num /= 4; | |
| console.log('devided by 2 => ' + num); | |
| }).catch(function(error) { | |
| console.error(erro); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment