是否存在扩展函数的承诺标准,如.all(),. finally()等 [英] Are there promise standards for extended functions like .all(), .finally(), etc

查看:61
本文介绍了是否存在扩展函数的承诺标准,如.all(),. finally()等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在扩展承诺功能的标准或新标准,例如 .all() .finally() .catch() .spread <) .settle()等等......

Are there standards or emerging standards for extended promise functions such as .all(), .finally(), .catch(), .spread(), .settle(), etc...

我知道Promises A +规范,但这只能解决 .then()我无法找到所有其他有用功能的标准。我熟悉jQuery,Q和Bluebird,并且所有这些之间存在明显的差异,这似乎应该是一个临时条件,因为一切都应该随着时间的推移而收敛到标准,因为实际上没有理由为类似的功能部分使用不同的名称。我知道jQuery甚至不完全是Promises A +兼容,但显然它是一个明确的目标,至少转向那个,但是所有其他有用的功能呢?

I know about the Promises A+ spec, but that only appears to deal with .then() and I can't find standards for all the other useful functions. I'm familiar with jQuery, Q and Bluebird and there are meaningful differences among all which seems like it should be a temporary condition as everything should converge to a standard over time since there's really no reason to have different names for similar pieces of functionality. I know jQuery isn't even fully Promises A+ compatible, but apparently it is a stated goal to at least move to that, but what about all the other useful functions?

我想要了解当前和未来标准开发的样子的动机是知道各个库中提供的当前功能更可能与未来标准一致,哪些不是这样我可以编写需要较少维护的代码这个领域在未来。我已经做了很多搜索,但似乎很难找到(对我而言)。我可以在ES6草案规范中看到 Promise.all(),但看不到其他任何内容。

My motivation for wanting to understand what the current and future standards development looks like is to know which current functions offered in the various libraries are more likely to be consistent with future standards and which are not so I can write code that will need less maintenance in this area in the future. I've done a bunch of searching and it seems to be a hard thing to find (for me anyway). I can see Promise.all() in an ES6 draft spec, but don't see any of the others.

是否有针对高级承诺函数的建议标准,例如 .all() .finally() .catch() .spread <) .settle()

Are there proposed standards for advanced promise functions such as .all(), .finally(), .catch(), .spread() and .settle()?

推荐答案


我知道Promises A +规范,但这似乎只是处理 .then()

是的。 Promises / A +规范的目的是详细说明then方法的行为,提供一个可互操作的基础,所有Promises / A +符合承诺的实现可以依赖于提供并且还描述了promise同化,即如何将类似promise的对象转换为自己库的真实Promise。总之,它通过指定最小接口来关注互操作性

Yes. The aim of the Promises/A+ spec is to "detail the behavior of the then method, providing an interoperable base which all Promises/A+ conformant promise implementations can be depended on to provide" and also describes promise assimilation, i.e. how to convert a promise-like object to a "real" Promise of your own library. In one word, it focuses on interoperability by speccing the minimum interface.


我找不到标准所有其他有用的功能。

I can't find standards for all the other useful functions.

是的。每个库都确定了自己的库。当许多实现中存在特定特征(并复制到特定特征)时,会出现标准。

Yes. Every library does define its own. "Standards" emerge when a particular feature is present in (and copied to) many implementations.


我想要了解当前的内容的动机并且未来的标准开发看起来就像知道各个库中提供的当前功能更可能与未来标准一致,而不是这样我可以编写将来在这个领域需要较少维护的代码。

My motivation for wanting to understand what the current and future standards development looks like is to know which current functions offered in the various libraries are more likely to be consistent with future standards and which are not so I can write code that will need less maintenance in this area in the future.

可能正在观看大型实施的问题讨论是最好的主意。但是,大多数提供的功能相对容易填充。

Probably watching the issue discussions of the big implementations is the best idea. However, most of the offered features are relatively easy to polyfill.

黄金标准将是ES6和ES7。定期检查esdescuss邮件列表,讨论功能,使用问题和新草稿。

The gold standard will be ES6 and ES7. Check the esdiscuss mailing list regularly for discussion of features, questions on the usage, and new drafts.


我可以看到Promise.all()在ES6草案规范中,但没有看到任何其他。

I can see Promise.all() in an ES6 draft spec, but don't see any of the others.

如果你仔细观察,促销部分详细信息:

If you look more closely, the Promise section details:


  • 承诺构造函数, Promise.reject Promise.resolve

  • Promise.all Promise.race

  • Promise.prototype.catch Promise.prototype.then

  • The Promise constructor, Promise.reject and Promise.resolve
  • Promise.all and Promise.race
  • Promise.prototype.catch and Promise.prototype.then

.finally() .catch() .spread() .settle()




  • 最后在es escucuss上讨论过(例如这里),但可能不会进入ES6。

  • 见上面的 catch

  • 点差被点差运算符取代并解构

  • 结算可以使用所有实现,或者至少使用非常接近的算法全部 spec

    • finally was discussed on esdiscuss (e.g. here), but probably won't make it into ES6.
    • see above for catch
    • spread is superseded by the spread operator and destructuring
    • settle could be implemented using all, or at least using an algorithm very close to the all spec
    • 这篇关于是否存在扩展函数的承诺标准,如.all(),. finally()等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆