From 235a1342f8ba885efbc7a5f12b2096511b63c403 Mon Sep 17 00:00:00 2001 From: grob Date: Tue, 30 Jun 2009 08:18:59 +0000 Subject: [PATCH] committed patch by Simon Oberhammer (adding forEach() to HitCollection, see http://dev.helma.org/bugs/show_bug.cgi?id=670) --- helma/Search.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/helma/Search.js b/helma/Search.js index 7464200e..478fd638 100644 --- a/helma/Search.js +++ b/helma/Search.js @@ -773,7 +773,27 @@ helma.Search.HitCollection = function(hits) { this.length = function() { return this.size(); }; - + + /** + * Executes a provided function once per hit. + * @param {Function} fun Function to execute for each element + * @param {Object} context Object to use as "this" when executing callback. + * @see https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array/ForEach + */ + this.forEach = function(func, context) { + if (typeof func != "function") { + throw new TypeError(); + } + var len = this.size(); + for (var i = 0; i < len; i += 1) { + var hit = this.get(i); + if (hit) { + func.call(context, hit, i, hits); + } + } + return; + }; + return this; };