By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,715 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,715 IT Pros & Developers. It's quick & easy.

instanceof operator

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
whitelined wrote:
How widely supported is the instanceof operator?
See
http://developer.mozilla.org/en/docs...nceof_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/libr...6z(VS.85).aspx, instanceof
is supported since JScript 5 which appeared with IE 5 I think.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2

P: n/a
On May 30, 11:35*am, whitelined wrote:
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.

Jun 27 '08 #3

P: n/a
whitelined wrote:
How widely supported is the instanceof operator? [...]
See http://PointedEars.de/es-matrix for updated version information about
this and other language features.
Many thanks
You are welcome.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.