RXJS 中的观察者和订阅者有什么区别?

what is the difference between observer and subscriber in RXJS?

RXJS中观察者和订阅者有什么区别?

见下方代码

// subscriber being used
const observable = new Observable(subscriber => {
  subscriber.next(1);
  subscriber.next(2);
})

// observer being used
const observable = new Observable(observer => {
  observer.next(1);
  observer.next(2);
})

在上面的上下文中观察者和订阅者有什么区别?

这些都是一样的。在这种情况下,subscriberobserver 只是为函数参数指定的名称。您可以将其命名为 anythingYouWant,它的功能相同:

const observable = new Observable(anythingYouWant => {
  anythingYouWant.next(1);
  anythingYouWant.next(2);
})