This fails because it cannot be used universally, and will result in
different behaviours accross browsers if used as the general case with a sub
case for |IE.
As Henry says this will fail with a typing error if object
is not an object.
I did not say that. I said that an - in - operation would throw an
exception if its subject (right hand side operand) was not an object.
The above is completely safe in ECMAScript terms when the - object -
parameter is not a host object (and also safe with the vast majority
of host objects) because if the value as a primitive it must have
truness to pass the first type-converting test and if it has truness
it can be implicitly type-converted into an object by the dot
operator.
Duck Typing wins out :-
function isElement( o)
{
return o && typeof o === "object" && o.nodeType == 1 &&
typeof o.tagName === "string"
}
<snip>
There is nothing in the ECMAScript bindings or the DOM documentation
that says that the object implementing any DOM interface may not be a
function object, so - typeof 0 === "object" - is insufficient.
When the last in-depth discussion of the faults of JQuery's -
isFunction - function was held here one of the issues with the code
was the fact that on some Mozilla/Firefox browsers -
document.createElement('object') - returned an object that reported
'function' from a - typeof - operation (and appeared to be callable
(even if an exception was thrown during the call), so apparently that
Element _is_ a function).