aboutsummaryrefslogtreecommitdiffstats
path: root/src/Angular.js
diff options
context:
space:
mode:
authorIgor Minar2010-11-24 21:12:52 -0800
committerIgor Minar2010-11-24 21:13:58 -0800
commit6b3b00e0953176598df2981191bb8264c435ab50 (patch)
treef202cb67a3333803b0ca6ec6580c0d738fbaa746 /src/Angular.js
parent921f7ce49e63c80bbae4d59e65c0d85bb5256370 (diff)
downloadangular.js-6b3b00e0953176598df2981191bb8264c435ab50.tar.bz2
docs for angular.foreach
Diffstat (limited to 'src/Angular.js')
-rw-r--r--src/Angular.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 3a7848e3..6347795e 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -566,6 +566,32 @@ var _undefined = undefined,
nodeName,
rngScript = /^(|.*\/)angular(-.*?)?(\.min)?.js(\?[^#]*)?(#(.*))?$/;
+/**
+ * @workInProgress
+ * @ngdoc function
+ * @name angular.foreach
+ * @function
+ *
+ * @description
+ * Invokes the `iterator` function once for each item in `obj` collection. The collection can either
+ * be 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. Optionally, `context` can be specified for the iterator function.
+ *
+ <pre>
+ var values = {name: 'misko', gender: 'male'};
+ var log = [];
+ angular.foreach(values, function(value, key){
+ this.push(key + ': ' + value);
+ }, log);
+ expect(log).toEqual(['name: misko', 'gender:male']);
+ </pre>
+ *
+ * @param {Object|Array} obj Object to iterate over.
+ * @param {function()} iterator Iterator function.
+ * @param {Object} context Object to become context (`this`) for the iterator function.
+ * @returns {Objet|Array} Reference to `obj`.
+ */
function foreach(obj, iterator, context) {
var key;
if (obj) {