From 6b3b00e0953176598df2981191bb8264c435ab50 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 24 Nov 2010 21:12:52 -0800 Subject: docs for angular.foreach --- src/Angular.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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. + * +
+ 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']);
+
+ *
+ * @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) {
--
cgit v1.2.3