angular.forEach obj parameter in callback function (#14953)

This commit is contained in:
Jakub 2017-03-10 07:28:42 +01:00 committed by Mohamed Hegazy
parent c12c733253
commit 2efe76ecf0
2 changed files with 5 additions and 4 deletions

View File

@ -587,7 +587,8 @@ namespace TestPromise {
function test_angular_forEach() {
const values: { [key: string]: string } = { name: 'misko', gender: 'male' };
const log: string[] = [];
angular.forEach(values, (value, key) => {
angular.forEach(values, (value, key, obj) => {
obj[key] = value;
this.push(key + ': ' + value);
}, log);
// expect(log).toEqual(['name: misko', 'gender: male']);

6
angular/index.d.ts vendored
View File

@ -97,7 +97,7 @@ declare namespace angular {
* @param iterator Iterator function.
* @param context Object to become context (this) for the iterator function.
*/
forEach<T>(obj: T[], iterator: (value: T, key: number) => any, context?: any): any;
forEach<T>(obj: T[], iterator: (value: T, key: number, obj: T[]) => void, context?: any): T[];
/**
* Invokes the iterator function once for each item in obj collection, which can be either an object or an array. The iterator function is invoked with iterator(value, key), where value is the value of an object property or an array element and key is the object property key or array element index. Specifying a context for the function is optional.
*
@ -107,7 +107,7 @@ declare namespace angular {
* @param iterator Iterator function.
* @param context Object to become context (this) for the iterator function.
*/
forEach<T>(obj: { [index: string]: T; }, iterator: (value: T, key: string) => any, context?: any): any;
forEach<T>(obj: { [index: string]: T; }, iterator: (value: T, key: string, obj: { [index: string]: T; }) => void, context?: any): { [index: string]: T; };
/**
* Invokes the iterator function once for each item in obj collection, which can be either an object or an array. The iterator function is invoked with iterator(value, key), where value is the value of an object property or an array element and key is the object property key or array element index. Specifying a context for the function is optional.
*
@ -117,7 +117,7 @@ declare namespace angular {
* @param iterator Iterator function.
* @param context Object to become context (this) for the iterator function.
*/
forEach(obj: any, iterator: (value: any, key: any) => any, context?: any): any;
forEach(obj: any, iterator: (value: any, key: any, obj: any) => void, context?: any): any;
fromJson(json: string): any;
identity<T>(arg?: T): T;