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

Function forEach

test/angular/1.7/angular.js:374–414  ·  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

372 */
373
374function forEach(obj, iterator, context) {
375 var key, length;
376 if (obj) {
377 if (isFunction(obj)) {
378 for (key in obj) {
379 if (key !== 'prototype' && key !== 'length' && key !== 'name' && obj.hasOwnProperty(key)) {
380 iterator.call(context, obj[key], key, obj);
381 }
382 }
383 } else if (isArray(obj) || isArrayLike(obj)) {
384 var isPrimitive = typeof obj !== 'object';
385 for (key = 0, length = obj.length; key < length; key++) {
386 if (isPrimitive || key in obj) {
387 iterator.call(context, obj[key], key, obj);
388 }
389 }
390 } else if (obj.forEach && obj.forEach !== forEach) {
391 obj.forEach(iterator, context, obj);
392 } else if (isBlankObject(obj)) {
393 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
394 for (key in obj) {
395 iterator.call(context, obj[key], key, obj);
396 }
397 } else if (typeof obj.hasOwnProperty === 'function') {
398 // Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
399 for (key in obj) {
400 if (obj.hasOwnProperty(key)) {
401 iterator.call(context, obj[key], key, obj);
402 }
403 }
404 } else {
405 // Slow path for objects which do not have a method `hasOwnProperty`
406 for (key in obj) {
407 if (hasOwnProperty.call(obj, key)) {
408 iterator.call(context, obj[key], key, obj);
409 }
410 }
411 }
412 }
413 return obj;
414}
415
416function forEachSorted(obj, iterator, context) {
417 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
annotateFunction · 0.70
createInjectorFunction · 0.70

Calls 4

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

Tested by

no test coverage detected