'of' vs 'from' operator

后端 未结 7 2088
栀梦
栀梦 2020-11-29 17:18

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

7条回答
  •  粉色の甜心
    2020-11-29 17:53

    It is important to note the difference between of and from when passing an array-like structure (including strings):

    Observable.of([1, 2, 3]).subscribe(x => console.log(x));
    

    would print the whole array at once.

    On the other hand,

    Observable.from([1, 2, 3]).subscribe(x => console.log(x));
    

    prints the elements 1 by 1.

    For strings the behaviour is the same, but at character level.

提交回复
热议问题