/Ugly/ + 'JavaScript'

A place for ugly, silly, or just-plain-crap JavaScript.

Browser Inference at its worst?

… or rather, feature-based browser detection, from which it is inferred that another feature/quality occurs (in this case, a time zone offset):

//remove time zone offset in IE  
if (window.ActiveXObject) {  
    obj[i].created_at = obj[i].created_at.replace(/[+]\d{4}/, "");  
}

Window haz property X? Browser must be E. Therefore, E must have unrelated feature Y.

Relevant feature detection would be better:

var canParseTimeOffsetWithoutDesignator = !isNaN(
    +new Date('Mon Jan 01 00:00:00 +0000 2000')
);

if (canParseTimeOffsetWithoutDesignator) {
    // ...
}

Something I never knew: IE appears to require a timezone designator along with the offset, so +0000 won’t do, but e.g. GMT+0000 will do fine.

Posted by James on 11 Sep 2011 | linky

Subscribe or follow @UglyJS!
.........
Fork then send a pull request to contribute.