then / promise

Bare bones Promises/A+ implementation
https://www.promisejs.org
MIT License
2.58k stars 312 forks source link

can Promise.resolve replace by code like this? #142

Closed miracle9312 closed 6 years ago

miracle9312 commented 6 years ago

Promise.resolve1 = function(value) { return new Promise(function(resolve, reject){ resolve(value); }) };

I have tested 3 cases like value={then:fn}, value=promise,value=''...;but I cannot find any differences between Promise.resolve1 with your Promise.resolve. could you please explain the differences for me. thx!

edef1c commented 6 years ago

Promise.resolve(x) is intended to behave equivalently to new Promise((resolve, reject) => resolve(x)), we've just got a bunch of performance tricks in our version that make use of implementation details.

miracle9312 commented 6 years ago

thanks,I get it, and your considerations in details inspires me a lot !