p1 will be a fulfilled promise with value 3. reject will be executed by the constructor, but it will not modify the promise because the promise is already resolved.
Promise.resolve(p1) is the same as p1.
1 2
> Promise.resolve(p1) === p1 true
Real promise constructed with new Promise constructor but throws inside the fulfill callback
The reject part will still be executed, but the result is a proper Promise that only has one immutable fulfilled status with the value 3. By contrast, if we use p3 as a promise and let is participate in a promise chain, there will be silly behaviours, i.e. both onFulfilled and onRejected will be called.
functionisThenable(v) { return v !== null && ( typeof v === "object" || typeof v === "function" ) && typeof v.then === "function" }
Use Promise.resolve to implement Promise.first
Requirement: ignore rejections and return a promise that resolves to the first fulfillment value among the promises; if all promises reject, reject the promise.