To understand this, first you can take a look at the predefined method of the JavaScript call function:
var person = { firstName:"John", lastName: "Doe", fullName: function() { return this.firstName + " " + this.lastName; } } var myObject = { firstName:"Mary", lastName: "Doe", } person.fullName.call(myObject);
The reason for calling the "call" is the function call in the "person" object and the transfer of the context into it "myObject".
Similarly, the reason for this call is βcallβ below:
const inputValues$ = _do.call(this._valueChanges, value => { this._userInput = value; if (this.editable) { this._onChange(value); } });
provides the context "this._valueChanges", but also provides a function that will be called the base in this context, that is, the second parameter, an anonymous function
value => { this._userInput = value; if (this.editable) { this._onChange(value); } }
In the example you use:
this._valueChanges is an Observerable input event
_do.call is intended to perform some side effects each time the event is input, then it will return a mirror image of the observed source Observable (observed event)
UPDATED Code example: https://plnkr.co/edit/dJNRNI?p=preview
About the do call:
You can call it observable as follows:
const source = Rx.Observable.of(1,2,3,4,5); const example = source .do(val => console.log(`BEFORE MAP: ${val}`)) .map(val => val + 10) .do(val => console.log(`AFTER MAP: ${val}`)); const subscribe = example.subscribe(val => console.log(val));
In this case, you do not need to pass the first parameter as an Observed context.
But when you call it from your place, as you said, you need to pass the first parameter as the βObservableβ that you want to call. It is different.
as @Fan Cheung pointed out, if you don't want to call it from your place, you can do it like this:
const inputValues$=this._valueChanges.do(value=>{ this._userInput = value; if (this.editable) { this._onChange(value); } })