Hides the identity of an observer.
(Observer): An observer that hides the identity of the specified observer.
{% if book.isPdf %}
function SampleObserver () {
Rx.Observer.call(this);
this.isStopped = false;
}
SampleObserver.prototype = Object.create(Rx.Observer.prototype);
SampleObserver.prototype.constructor = SampleObserver;
Object.defineProperties(SampleObserver.prototype, {
onNext: {
value: x => {
if (!this.isStopped) {
console.log(`Next: ${x}`);
}
}
},
onError: {
value: err => {
if (!this.isStopped) {
this.isStopped = true;
console.log(`Error: ${err}`);
}
}
},
onCompleted: {
value: () => {
if (!this.isStopped) {
this.isStopped = true;
console.log('Completed');
}
}
}
});
var sampleObserver = new SampleObserver();
var source = sampleObserver.asObserver();
console.log(source === sampleObserver);
// => false
{% else %}
{% endif %}
{% if book.isPdf %}
{% else %}
- rx.js
{% endif %}