[[Resolve]] (promise, x)if x is Promise, make promise accept the state of x. Note 4:
with x as parameter.
if x is in waiting state, promise shall remain in waiting state until x is executed or rejected
if x is in execution state, execute promise
if x is in reject state, reject promise
if x is not an object or function, execute promise
the above is excerpted from the Promise/A+ specification
if you follow the description in the specification, then when x = Promise.resolve (10), the behavior of the two should be the same. He will take the value of promise in the execution state and do a resolve. This whole process should be similar to grammatical sugar? But the truth seems to be a little biased
Let"s look at a piece of code
new Promise((resolve, reject) => {
let a = new Promise(resolve => {
resolve(10)
})
let b = new Promise(resolve => {
let c = Promise.resolve(10)
resolve(c)
})
console.log(a)
console.log(b)
Promise.resolve(0)
.then(() => {
console.log("micro1")
console.log(b)
})
.then(() => {
console.log("micro2")
console.log(b)
})
setTimeout(() => {
console.log("marco")
console.log(b)
})
})
this is the output
let b = new Promise(resolve => {
Promise.resolve(10).then(res => {
resolve(res)
})
})