Bug 537 - HopObject.forEach should copy Array.forEach
: HopObject.forEach should copy Array.forEach
Status: NEW
: Helma
HopObject Functionality
: CVS trunk
: Other Windows
: P1 normal
: ---
Assigned To:
:
:
:
  Show dependency treegraph
 
Reported: 2007-07-28 00:52 by
Modified: 2007-07-28 01:26 (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2007-07-28 00:52:42
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.
------- Comment #1 From 2007-07-28 01:26:34 -------
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.