diff --git a/spec/Observable-spec.ts b/spec/Observable-spec.ts index afafcf0b3c..7697f25d28 100644 --- a/spec/Observable-spec.ts +++ b/spec/Observable-spec.ts @@ -30,7 +30,7 @@ describe('Observable', () => { const expected = [1, 2, 3]; const result = Observable.of(1, 2, 3).forEach(function (x) { expect(x).toBe(expected.shift()); - }, null, Promise) + }, Promise) .then(done); expect(typeof result.then).toBe('function'); @@ -39,7 +39,7 @@ describe('Observable', () => { it('should reject promise when in error', (done: DoneSignature) => { Observable.throw('bad').forEach((x: any) => { done.fail('should not be called'); - }, null, Promise).then(() => { + }, Promise).then(() => { done.fail('should not complete'); }, (err: any) => { expect(err).toBe('bad'); @@ -65,18 +65,6 @@ describe('Observable', () => { }); }); - it('should accept a thisArg argument', (done: DoneSignature) => { - const expected = [1, 2, 3]; - const thisArg = {}; - const result = Observable.of(1, 2, 3).forEach(function (x) { - expect(this).toBe(thisArg); - expect(x).toBe(expected.shift()); - }, thisArg, Promise) - .then(done); - - expect(typeof result.then).toBe('function'); - }); - it('should reject promise if nextHandler throws', (done: DoneSignature) => { const results = []; Observable.of(1, 2, 3).forEach((x: number) => { diff --git a/src/Observable.ts b/src/Observable.ts index 98f25b3335..94a1e3a055 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -213,12 +213,11 @@ export class Observable implements CoreOperators { /** * @method forEach * @param {Function} next a handler for each value emitted by the observable - * @param {any} [thisArg] a `this` context for the `next` handler function * @param {PromiseConstructor} [PromiseCtor] a constructor function used to instantiate the Promise * @return {Promise} a promise that either resolves on observable completion or * rejects with the handled error */ - forEach(next: (value: T) => void, thisArg: any, PromiseCtor?: typeof Promise): Promise { + forEach(next: (value: T) => void, PromiseCtor?: typeof Promise): Promise { if (!PromiseCtor) { if (root.Rx && root.Rx.config && root.Rx.config.Promise) { PromiseCtor = root.Rx.config.Promise; @@ -235,7 +234,7 @@ export class Observable implements CoreOperators { return new PromiseCtor((resolve, reject) => { source.subscribe((value: T) => { - const result: any = tryCatch(next).call(thisArg, value); + const result: any = tryCatch(next)(value); if (result === errorObject) { reject(errorObject.e); }