Created
November 18, 2016 08:34
-
-
Save choru-k/0c312b7cfb50a70d83d01bf9b7e4c025 to your computer and use it in GitHub Desktop.
promise chain test 3
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
var _promise1 = function (param) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
console.log('ok1'); | |
resolve(param); | |
}, 100); | |
}); | |
}; | |
var _promise2 = function (param) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
console.log('ok2'); | |
resolve(param); | |
}, 100); | |
}); | |
}; | |
var param = true; | |
_promise1(param) | |
.then(function (param) { | |
if (param) { | |
return _promise2(true) | |
} return true | |
}).then(function() { | |
console.log('ok3') | |
}); | |
// param === true | |
// Result | |
// ok1 | |
// ok2 | |
// ok3 | |
// param === false | |
// Result | |
// ok1 | |
// ok3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
오케이