Bugzilla – Bug 537
HopObject.forEach should copy Array.forEach
Last modified: 2007-07-28 01:26:34
You need to log in before you can comment on or make changes to this bug.
The reference describes HopObject.forEach(), but bizarrely compared to Spidermonkey's/Rhino's Array.forEach (though it may be only an English issue). Regardless, HopObject.forEach doesn't seem to exist. (I got a TypeError when I tried to use it on one of my HopObject-extending prototypes.) It seems to me that HopObject.forEach should exist and should work as exactly like Array.forEach as possible. Fortunately, Mozilla offers the code they use to implement Array.forEach at <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:forEach>, and it's easily modified to work with HopObjects, like so: HopObject.prototype.forEach = function(fun /*, thisp*/) { // forEach prototype slightly modified from Mozilla var tmp; var len = this.count(); if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (tmp = this.get(i)) fun.call(thisp, tmp, i, this); } }; This is in the Helma 1.6 release with an updated rhino.jar from zumbrunn to fix the e4x attributes issue.
just learned that HopObject.forEach is in core/HopObject.js. I've modified the summary to say that HopObject.forEach should more carefully clone Array.forEach. The function above should still do the trick.