Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The return of the .then function will be the resolved value of the promise.
- # tambahkan await sebelum initPromise jika mau menunggu proses
- function initPromise() {
- return new Promise(function(res, rej) {
- res("initResolve")
- })
- }
- initPromise()
- .then(function(result) {
- console.log(result) // "initResolve"
- return "normalReturn"
- })
- .then(function(result) {
- console.log(result) // "normalReturn"
- })
- # If the .then function returns a Promise, then the resolved value of that chained promise is passed to the following .then.
- function initPromise() {
- return new Promise(function(res, rej) {
- res("initResolve")
- })
- }
- initPromise()
- .then(function(result) {
- console.log(result) // "initResolve"
- return new Promise(function(resolve, reject) {
- setTimeout(function() {
- resolve("secondPromise")
- }, 1000)
- })
- })
- .then(function(result) {
- console.log(result) // "secondPromise"
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement