Firefox 3 Arrays: No, You’re Not Insane

I just spent 20 minutes in IRC with Wolfram staring down one of those situations where you keep swearing under your breath “println isn’t broken….println isn’t broken….println is NOT broken”.

Catch this fun gem from FF3b2:


>>> typeof []
"object"
>>> var a = [];
>>> var b = new Array();
>>> a.constructor == b.constructor
false
>>> c = [];
[]
>>> c.constructor == a.constructor
true
>>> d = new Array();
[]
>>> b.constructor == d.constructor;
true
>>> b.constructor == a.constructor;
false

WTF?

5 Comments

  1. Posted February 18, 2008 at 9:31 am | Permalink

    Confirmed on Firefox 3 Beta 3. Both print out Array() as their constructor, but apparently they’re not considered equal. WTF?

  2. Posted February 18, 2008 at 3:49 pm | Permalink

    In short: ([] instanceof Array) gives ‘false’

    I wonder if this has anything to do with the protection against JavaScript Hijacking that they put in to prevent people from stealing data by redefining the Array constructor?

  3. Posted February 18, 2008 at 11:33 pm | Permalink

    I guess working with Spidermonkey has corrupted me. This is wrong, but I doesn’t seem like a particularly weird way to fail, to me.

  4. Posted February 19, 2008 at 8:35 am | Permalink

    According to Wolfram’s comment on Ajaxian, this time println *is* broken. And I’ve confirmed this too. [].constructor == new Array().constructor will evaluate to true if you try this in Error Console instead of Firebug.

  5. Posted February 19, 2008 at 8:37 am | Permalink

    Wolfram also let me know today that it’s only firebug…I was wondering why all of Dojo hadn’t broken = )

One Trackback

  1. […] Alex’s blog entry he posted the problem with Firefox3 beta3! In […]