[Javascript] RES: (no subject)

liorean liorean at gmail.com
Wed Aug 29 18:52:33 CDT 2007


On 30/08/2007, Scott Reynen <scott at randomchaos.com> wrote:
> On Aug 29, 2007, at 5:17 PM, liorean wrote:
>
> >>>> var ie=(document.all);
> >>
> >>> Browser sniffing is far too fragile - I suggest you use object
> >>> detection instead.
> >>
> >> Uh, that *is* "object detection", is it not??
> >
> > Nope. Object detection means you are detecting whether objects you can
> > use for different paths exist. But this is not used that way - sure,
> > it's still detecting whether objects exists, but not for the purpose
> > of choosing whether to use them or use another path. This is just
> > using detection of objects to try to determine which browser is
> > running, and then choosing path based on browser.
>
> But when the path chosen "based on the browser" is entirely
> restricted to the objects being tested, the two are functionally
> identical.  I suspect you're just getting distracted by the variable
> names.

The variable names tells us a bit of how the original coder thought of
them and their use, but yes, you're right. The code snippet I read was
from David Hucklesby's mail (I didn't read the entire thread since the
earlier mails were already marked read from my last time), and  didn't
even contain any use of the variable, just the setting of it.

> What if we changed
>
> var ie=(document.all);
> [...]
> if(ie) object=eval('document.all.'+element+'.style');
>
> to
>
> var supportsDocumentAll=(document.all);
> [...]
> if(supportsDocumentAll) object=eval('document.all.'+element+'.style');
>
> Would you still call that browser sniffing?

No, I'd just call it bad coding style and for entirely different
reasons (I'm sure you can guess why).
-- 
David "liorean" Andersson



More information about the Javascript mailing list