Nicholas Jamieson
1 min readOct 27, 2017

--

Thanks for the feedback.

Library authors are encouraged to use call as doing so does not involve patching the operator into Observable.prototype. Which means that consumers of the library cannot become dependent upon the library’s patching of the prototype.

If the reason is still unclear, you might want to have a look at the explanation given by Jay Phelps in this issue.

The call example imports map from rxjs/operator/map and if you look at its implementation:

export function map<T, R>(
this: Observable<T>,
project: (value: T, index: number) => R,
thisArg?: any
): Observable<R> {
return higherOrderMap(project, thisArg)(this);
}

You’ll see that it references this — so it must be called with a context. And that’s why call is needed; this is the observable instance to which the operator is applied.

Importing map from rxjs/operator/map does not add the operator to the prototype, so it cannot be called in the chained manner.

--

--

Nicholas Jamieson
Nicholas Jamieson

Written by Nicholas Jamieson

RxJS core team member; front-end developer; mentor; speaker; open-source contributor

Responses (1)