Closed libook closed 3 years ago
const theObject = { "a": 7, }; const thePromise = new Promise((resolve, reject) => { resolve(theObject); }); // -> Promise instance object thePromise.then(value => { console.log(value === theObject); // -> true console.log(value); // -> { a: 7 } })
The value which is resolved from thePromise is exactly theObject.
value
thePromise
theObject
How about input another Promise into the resolve function?
Promise
resolve
const theObject = new Promise((resolve, reject) => { resolve(7); }); // -> Promise instance object const thePromise = new Promise((resolve, reject) => { resolve(theObject); }); // -> Promise instance object thePromise.then(value => { console.log(value === theObject); // -> false console.log(value); // -> 7 })
If the value (which is inputted into resolve function) is a thenable (i.e. has a "then" method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise the returned promise will be fulfilled with the value.
– Promise.resolve() on MDN
The specification is ECMAScript 25.6.1.3.2 Promise Resolve Functions. But it is not quite human-friendly.
@denysdovhan Finally. Conflicts are resolved. Please review.
Also updated information from MDN.
Thank you!
resolve() won't return Promise instance
The
value
which is resolved fromthePromise
is exactlytheObject
.How about input another
Promise
into theresolve
function?💡 Explanation:
– Promise.resolve() on MDN
The specification is ECMAScript 25.6.1.3.2 Promise Resolve Functions. But it is not quite human-friendly.