ITADN

Exposing `resolve` and `reject`

#21ClosedFrameMuse 创建于 2023-10-22
F
FrameMusecommented
Why having a new method like `Promise.withResolvers` if we could expose `resolve` and `reject` instead? Also `resolve` and `reject` can be exposed as getters to avoid modification. I'm not sure about consequences, but something tells me it's okay to do so since they were private and now they are public - no interference. Using traditional method or `Promise.withResolvers` will do the same staff anyway. ### Example Instead of ```js const { promise, resolve, reject } = Promise.withResolvers(); ``` We will get ```js const promise = new Promise(); promise.resolve(...); promise.reject(...); ```
关闭于 2023-10-23 8 条评论