'of' vs 'from' operator

后端 未结 7 2128
栀梦
栀梦 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:32

    from: Create observable from array, promise or iterable. Takes only one value. For arrays, iterables and strings, all contained values will be emitted as a sequence

    const values = [1, 2, 3];
    from(values); // 1 ... 2 ... 3
    

    of: Create observable with variable amounts of values, emit values in sequence, but arrays as single value

    const values = [1, 2, 3];
    of(values, 'hi', 4, 5); // [1, 2, 3] ... 'hi' ... 4 ... 5
    

提交回复
热议问题