Hi,
How widely supported is the instanceof operator?
It was introduced into ECMAScript in the 3rd edition of the
specification (end of 1999), and is now very widely supported.
Is there an alternative
to seeing if an object is an instance of a constructor?
There is no sense in which javascript objects are "an instance of a
constructor". The nearest you would get to that is saying that an
object was created using a constructor, and the - instanceof -
operator does not tell you that. Javascript's - instanceof - operator
determines whether the [[Prototype]] of an object is the same object
as the object currently assigned to the - prototype - property of a
function. As the latter is runtime assignable a false result form an -
instanceof - operation does not necessarily mean that the object was
not created using the function as a constructor. And as the same
object may be assigned to the - prototype - properties of many
functions a true result from an - instanceof - operation does not
necessarily mean that the object was constructed using the function as
a constructor.
The result is that if what you are writing is so chaotic by design
that you need to determine the type of an object at runtime the -
instanceof - operation is not going to be of much help in doing so.