Hi again,

Sorry, I was talking about Prototype 1.7's version of `isArray`. I
suddenly had a thought just now, so I checked and found that Prototype
1.6 used a different (and naive) definition which has known issues;
presumably those issues are why 1.7's version has been updated. So if
you're using 1.6, you may well see a false negative on a real array
instance. (Specifically, any array received from another window will
result in a false negative.) I'm surprised that 1.6 had that problem,
but it's good to see that 1.7 fixes it.

If you want to apply the fix to your projects without upgrading from
1.6 to 1.7, here's a cheap and easy way:

(function() {
    var toString = Object.prototype.toString;
    Object.isArray = function(obj) {
        return toString.call(obj) === "[object Array]"; //
Capitalization matters

T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Oct 23, 12:54 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> On Oct 23, 6:25 am, buda <www...@pochta.ru> wrote:
> > I've noticed that library's isArray not worked properly sometimes.
> When? A statement like that really requires data. I suspect where you
> haven't seen it work, the object genuinely isn't an array.
> Prototype's `Object.isArray` function relies on the JavaScript engine
> correctly implementing the specification for
> `Object.prototype.toString` (Section[1]). I've never met an
> engine that didn't implement that correctly. In contrast, your
> implementation gives false negatives on any browser that hasn't yet
> implemented the new `forEach` array prototype method from ECMAScript5
> (so, IE8 and downward), and gives false positives on any object that
> just happens to have a property called `forEach`. Respectfully, the
> Prototype implementation is much more robust.
> [1]http://es5.github.com/#x15.2.4.2
> --
> T.J. Crowder
> Independent Software Engineer
> tj / crowder software / com
> www / crowder software / com

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to