Omi: Dynamic Interactions Manager



IE7 + Prototype + comma = “‘undefined’ is null or not an object”

So again an infuriating bug, all down to this thing: , <–

So whenever you’re iterating (Enumerable.each() in this case) check that you haven’t got a superfluous comma in the object that you’re iterating through.
Normally this gets caught as a syntax error, but, because this code was being AJAXed, this didn’t happen and an obscure runtime error occured, buried deep within Prototype (inside 10 levels of anonymous functions)

Firefox it seems is much more lenient than IE in this case as it didn’t throw any error at all, simply ignoring the comma. Again the age old debate about fixing broken code rises. I think IE got it more right in this case. Markup (HTML) is a different issue - that should be corrected (though use XHTML whenever possible), but when it comes to code you need the extra safety. In a perfect world code thats AJAXed would also throw syntax errors.


Comments

  1. 1 pete says:

    you absolute legend!! this fixed the problem that almost made me bald!! cheers :-)

    Posted November 23, 2008, 1:01 pm
  2. 2 omi says:

    Just my way of giving back to the internet that has solved many of my own obscure problems :)

    Posted December 4, 2008, 1:03 am

Leave a Comment

(required)

(required)



Formatting your comment
Back to Top | Textarea: Larger | Smaller