r9838 - apps/modules/trunk/helma
[email protected] Tue, 30 Jun 2009 10:18:59 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090630081859.8B04E3D0E3@mia> |
Author: robert
Date: 2009-06-30 10:18:59 +0200 (Tue, 30 Jun 2009)
New Revision: 9838
Modified:
apps/modules/trunk/helma/Search.js
Log:
committed patch by Simon Oberhammer (adding forEach() to HitCollection, see http://dev.helma.org/bugs/show_bug.cgi?id=670)
Details at http://dev.helma.org/trac/helma/changeset/9838
Modified: apps/modules/trunk/helma/Search.js
===================================================================
--- apps/modules/trunk/helma/Search.js 2009-06-17 15:15:12 UTC (rev 9837)
+++ apps/modules/trunk/helma/Search.js 2009-06-30 08:18:59 UTC (rev 9838)
@@ -773,7 +773,27 @@
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;
};