instanceof operator

W

whitelined

Hi,

How widely supported is the instanceof operator? Is there an alternative
to seeing if an object is an instance of a constructor?

Many thanks

Regards

Aaron
 
M

Martin Honnen

whitelined said:
How widely supported is the instanceof operator?

See
http://developer.mozilla.org/en/doc...erators:Special_Operators:instanceof_Operator
it has been implemented first in JavaScript 1.4 so for Mozilla browser
anything from Netscape 6 and later, Mozilla 1.0, Firefox 1.0 supports it
as those browser have JavaScript 1.5 or later.
For MS JScript see
http://msdn.microsoft.com/en-us/library/zh0zb36z(VS.85).aspx, instanceof
is supported since JScript 5 which appeared with IE 5 I think.
 
H

Henry

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top