JavaScript中的observable和promise之间有什么区别? [英] What are the differences between observables and promises in JavaScript?
问题描述
所以我已经读过,在一些即将推出的JavaScript MVC中,observables正在寻求超越承诺:
So i've read that observables are looking to overtake promises in terms of usage in some of upcoming JavaScript MVC's:
- Angular 2.0
- Falcor used by Netflix
observables和promises有什么区别?
What is the difference between observables and promises?
更新:道歉!删除了我的虚假陈述。
Updated: Apologies! removed my falsy statement.
推荐答案
observables和promises有什么区别?
What is the difference between observables and promises?
简单地说:一个promise以异步方式解析为单个值,一个observable解析为(或发出)多个值异步(随着时间的推移)。
Simply put: A promise resolves to a single value asynchronously, an observable resolves to (or emits) multiple values asynchronously (over time).
具体示例:
- 承诺:来自Ajax调用的响应
- 可观察:点击事件
更多信息可以是在此处找到: http://reactivex.io/intro.html
More information can be found here: http://reactivex.io/intro.html
我读过observables希望超越承诺
i've read that observables are looking to overtake promises
不太可能。对于某些问题,Observable可能是更好的解决方案,但这并不能使承诺过时(如果这就是你的意思)。
Unlikely. Observables might be the better solution to certain problems, but that doesn't make promises obsolete (if that's what you mean).
这篇关于JavaScript中的observable和promise之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!