MCPcopy
hub / github.com/angular-ui/ui-router / forEach

Function forEach

test/angular/1.4/angular.js:326–368  ·  view source on GitHub ↗

* @ngdoc function * @name angular.forEach * @module ng * @kind function * * @description * 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, obj)`, where `value` *

(obj, iterator, context)

Source from the content-addressed store, hash-verified

324 */
325
326function forEach(obj, iterator, context) {
327 var key, length;
328 if (obj) {
329 if (isFunction(obj)) {
330 for (key in obj) {
331 // Need to check if hasOwnProperty exists,
332 // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
333 if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
334 iterator.call(context, obj[key], key, obj);
335 }
336 }
337 } else if (isArray(obj) || isArrayLike(obj)) {
338 var isPrimitive = typeof obj !== 'object';
339 for (key = 0, length = obj.length; key < length; key++) {
340 if (isPrimitive || key in obj) {
341 iterator.call(context, obj[key], key, obj);
342 }
343 }
344 } else if (obj.forEach && obj.forEach !== forEach) {
345 obj.forEach(iterator, context, obj);
346 } else if (isBlankObject(obj)) {
347 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
348 for (key in obj) {
349 iterator.call(context, obj[key], key, obj);
350 }
351 } else if (typeof obj.hasOwnProperty === 'function') {
352 // Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
353 for (key in obj) {
354 if (obj.hasOwnProperty(key)) {
355 iterator.call(context, obj[key], key, obj);
356 }
357 }
358 } else {
359 // Slow path for objects which do not have a method `hasOwnProperty`
360 for (key in obj) {
361 if (hasOwnProperty.call(obj, key)) {
362 iterator.call(context, obj[key], key, obj);
363 }
364 }
365 }
366 }
367 return obj;
368}
369
370function forEachSorted(obj, iterator, context) {
371 var keys = Object.keys(obj).sort();

Callers 15

copyFunction · 0.70
parseKeyValueFunction · 0.70
toKeyValueFunction · 0.70
angularInitFunction · 0.70
bootstrapFunction · 0.70
jqLiteBuildFragmentFunction · 0.70
jqLiteOffFunction · 0.70
jqLiteRemoveClassFunction · 0.70
jqLiteAddClassFunction · 0.70
angular.jsFile · 0.70
HashMapFunction · 0.70
annotateFunction · 0.70

Calls 4

isArrayFunction · 0.85
isFunctionFunction · 0.70
isArrayLikeFunction · 0.70
isBlankObjectFunction · 0.70

Tested by

no test coverage detected