Re: isElement - determining if an object is an element



On Jul 30, 2:46 pm, Aaron Gray wrote:
<snip>
function isElement( o)
{
if (!isIE)
return o instanceof Element
else
return o && o.nodeType == 1 && o.tagName != undefined
}
<snip>

Why branch for this? If the second test is ever good enough it is
always good enough.

Exact equality (===) with 1 would be more precise than type-converting
equality and reduce the possible false positives.

But overall what it the point? If you inferred from a true result from
a call to your - isElement - method that the object implemented the
whole W3C Core DOM (Level 1 or 2) Element interface you would be wrong
in a number of cases. It would make more sense to decide what features
you wanted from such an element and test for those alone on a basis
driven by need.
.



Relevant Pages