of / just

函数签名: of(...values, scheduler: Scheduler): Observable

按顺序发出任意数量的值。

示例

示例 1: 发出数字序列

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { of } from 'rxjs';
// 依次发出提供的任意数量的值
const source = of(1, 2, 3, 4, 5);
// 输出: 1,2,3,4,5
const subscribe = source.subscribe(val => console.log(val));
示例 2: 发出对象、数组和函数

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { of } from 'rxjs';
// 出任意类型值
const source = of({ name: 'Brian' }, [1, 2, 3], function hello() {
  return 'Hello';
});
// 输出: {name: 'Brian}, [1,2,3], function hello() { return 'Hello' }
const subscribe = source.subscribe(val => console.log(val));

其他资源

:file_folder: 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/of.ts

results matching ""

    No results matching ""