nzakas / understandinges6

Content for the ebook "Understanding ECMAScript 6"
5.45k stars 796 forks source link

Fix:Ch11:Pass a promise when Creating Settled Promises #460

Closed yikayiyo closed 3 years ago

yikayiyo commented 3 years ago

Ch11

Creating Settled Promises

Before Non-Promise Thenables, there is a note.

If you pass a promise to either the Promise.resolve() or Promise.reject() methods, the promise is returned without modification.

I think it is confusing and try some code.

let p3 = Promise.reject("xxx");

let p4 = Promise.resolve(p3);

console.log(p3 === p4);  // true. Here Promise.resolve() returns a rejected promise.

let p6 = Promise.reject(p3)

console.log(p6 === p3);  // false. Here is a modification. A new rejected promise is returned.

Hope this is helpful.

nzakas commented 3 years ago

Thanks. That’s a bit of an edge case, and I don’t accept direct edits of anything other than typos, so I’m leaving this as-is.