“of"与“from"运算符 [英] 'of' vs 'from' operator
问题描述
Observable.of
和 Observable.from
之间的唯一区别是参数格式吗?像 Function.prototype.call
和 Function.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屋!