MCPcopy Index your code
hub / github.com/angular-ui/ui-router / forEach

Function forEach

test/angular/1.5/angular.js:310–352  ·  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

308 */
309
310function forEach(obj, iterator, context) {
311 var key, length;
312 if (obj) {
313 if (isFunction(obj)) {
314 for (key in obj) {
315 // Need to check if hasOwnProperty exists,
316 // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
317 if (key !== 'prototype' && key !== 'length' && key !== 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
318 iterator.call(context, obj[key], key, obj);
319 }
320 }
321 } else if (isArray(obj) || isArrayLike(obj)) {
322 var isPrimitive = typeof obj !== 'object';
323 for (key = 0, length = obj.length; key < length; key++) {
324 if (isPrimitive || key in obj) {
325 iterator.call(context, obj[key], key, obj);
326 }
327 }
328 } else if (obj.forEach && obj.forEach !== forEach) {
329 obj.forEach(iterator, context, obj);
330 } else if (isBlankObject(obj)) {
331 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
332 for (key in obj) {
333 iterator.call(context, obj[key], key, obj);
334 }
335 } else if (typeof obj.hasOwnProperty === 'function') {
336 // Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
337 for (key in obj) {
338 if (obj.hasOwnProperty(key)) {
339 iterator.call(context, obj[key], key, obj);
340 }
341 }
342 } else {
343 // Slow path for objects which do not have a method `hasOwnProperty`
344 for (key in obj) {
345 if (hasOwnProperty.call(obj, key)) {
346 iterator.call(context, obj[key], key, obj);
347 }
348 }
349 }
350 }
351 return obj;
352}
353
354function forEachSorted(obj, iterator, context) {
355 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