committed patch by Simon Oberhammer (adding forEach() to HitCollection, see http://dev.helma.org/bugs/show_bug.cgi?id=670)

This commit is contained in:
grob 2009-06-30 08:18:59 +00:00
parent 052b6fc4bb
commit 235a1342f8

View file

@ -774,6 +774,26 @@ helma.Search.HitCollection = function(hits) {
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;
};