Issue
At rxjs,
export function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>;
I cannot find usage of thisArg: A
.
Solution
It's the same purpose as in Array.prototype.map
: context is lost when you pass a function as an argument.
class Value {
constructor (public value:number) {}
addValue (x:number) { return this.value + x; }
}
const five = new Value(5);
[1, 2, 3].map(five.addValue); // Error because this is undefined
[1, 2, 3].map(five.addValue, five); // [6, 7, 8]
RxJS example
const source = Rx.Observable.from([1, 2, 3]);
source.map(five.addValue); // NaN...NaN...NaN
source.map(five.addValue, five); // 6...7...8
Answered By - geoffrey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.