instanceof operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • whitelined

    instanceof operator

    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
  • Martin Honnen

    #2
    Re: instanceof operator

    whitelined wrote:
    How widely supported is the instanceof operator?
    See
    The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

    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

    Comment

    • Henry

      #3
      Re: instanceof operator

      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.

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: instanceof operator

        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

        Comment

        Working...