“of"与“from"运算符 [英] 'of' vs 'from' operator

查看:60
本文介绍了“of"与“from"运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Observable.ofObservable.from 之间的唯一区别是参数格式吗?像 Function.prototype.callFunction.prototype.apply?

Is the only difference between Observable.of and Observable.from the arguments format? Like the Function.prototype.call and Function.prototype.apply?

Observable.of(1,2,3).subscribe(() => {})
Observable.from([1,2,3]).subscribe(() => {})

推荐答案

不太清楚.将数组传递给 Observable.from 时,它与 Observable.of 之间的唯一区别是传递参数的方式.

Not quite. When passing an array to Observable.from, the only difference between it and Observable.of is the way the arguments are passed.

但是,Observable.from 将接受 参数

要转换的可订阅对象、Promise、Observable-like、Array、iterable 或 array-like 对象

a subscribable object, a Promise, an Observable-like, an Array, an iterable or an array-like object to be converted

Observable.of 没有类似的行为 - 它总是只接受值并且不执行转换.

There is no similar behaviour for Observable.of - which always accepts only values and performs no conversion.

这篇关于“of"与“from"运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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