Why (new RegExp) type is function not object

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

    Why (new RegExp) type is function not object

    typeof new RegExp
    ----------------------------------------------------
    Why (new RegExp) type is function not object

    very thanks for you consulation
  • RobG

    #2
    Re: Why (new RegExp) type is function not object

    EME wrote:
    typeof new RegExp
    ----------------------------------------------------
    Why (new RegExp) type is function not object
    >
    very thanks for you consulation
    A function is an object. The ECMA spec section 11.4.3 says that the
    typeof operator returns 'function' for objects that are functions[1],
    and 'object' for objects that aren't functions.

    Note that IE doesn't do that, it returns 'object' for functions.


    1. It actually says "native and implements [[call]]", but it means
    function. :-)


    --
    Rob
    "We shall not cease from exploration, and the end of all our
    exploring will be to arrive where we started and know the
    place for the first time." -- T. S. Eliot

    Comment

    • AKS

      #3
      Re: Why (new RegExp) type is function not object

      On 8 ÄÅË, 06:33, EME <megaupload.sh. ..@gmail.comwro te:
      typeof new RegExp
      ----------------------------------------------------
      Why (new RegExp) type is function not object
      >
      Actually, only SpiderMonkey creates function, evaluating -new RegExp-
      expression. It's more like extension of the engine since the
      calculated object has no properties length and prototype.

      Comment

      • AKS

        #4
        Re: Why (new RegExp) type is function not object

        On 8 ÄÅË, 09:03, RobG <rg...@iinet.ne t.auwrote:
        >
        Note that IE doesn't do that, it returns 'object' for functions.
        >
        I hope you meant: "it returns 'object' for host functions".


        Comment

        • EME

          #5
          Re: Why (new RegExp) type is function not object

          for furthur more,i have detail test below:
          typeof new RegExp //result 'function' in Firefox, 'object' in IE6
          new RegExp instanceof Function //result false in Firefox

          (new RegExp)() in Firefox is same as (new RegExp).exec()

          Comment

          • David Mark

            #6
            Re: Why (new RegExp) type is function not object

            On Dec 8, 12:30 am, AKS <aksus...@yande x.ruwrote:
            On 8 ÄÅË, 09:03, RobG <rg...@iinet.ne t.auwrote:
            >
            >
            >
            Note that IE doesn't do that, it returns 'object' for functions.
            >
            I hope you meant: "it returns 'object' for host functions".
            I would think so.

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: Why (new RegExp) type is function not object

              David Mark wrote:
              On Dec 8, 2:55 am, EME <megaupload.sh. ..@gmail.comwro te:
              >new RegExp instanceof Function //result false in Firefox
              >
              It isn't an instance of Function (it is an instance of RegExp.)
              It isn't an instance of anything, as that would imply class-based inheritance.


              PointedEars
              --
              realism: HTML 4.01 Strict
              evangelism: XHTML 1.0 Strict
              madness: XHTML 1.1 as application/xhtml+xml
              -- Bjoern Hoehrmann

              Comment

              • David Mark

                #8
                Re: Why (new RegExp) type is function not object

                On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                wrote:
                David Mark wrote:
                On Dec 8, 2:55 am, EME <megaupload.sh. ..@gmail.comwro te:
                new RegExp instanceof Function //result false in Firefox
                >
                It isn't an instance of Function (it is an instance of RegExp.)
                >
                It isn't an instance of anything, as that would imply class-based inheritance.
                >
                You are kidding right? The operator quoted above that sentence should
                explain why I used that terminology.

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: Why (new RegExp) type is function not object

                  David Mark wrote:
                  On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                  wrote:
                  >David Mark wrote:
                  >>On Dec 8, 2:55 am, EME <megaupload.sh. ..@gmail.comwro te:
                  >>>new RegExp instanceof Function //result false in Firefox
                  >>It isn't an instance of Function (it is an instance of RegExp.)
                  >It isn't an instance of anything, as that would imply class-based inheritance.
                  >
                  You are kidding right?
                  I am not.
                  The operator quoted above that sentence should explain why I used that terminology.
                  The operator above was borrowed from Java, a programming language that
                  uses only class-based inheritance, to ease programming in JavaScript for
                  developers that a familiar with Java. However, `instanceof' is only a
                  name, not a hint regarding the underlying concept of the operation in
                  implementations of Edition 3 of the ECMAScript Language Specification.
                  It is therefore inappropriate to speak of objects as instances of their
                  constructors.

                  In programming, inheritance refers to passing down characteristics from a parent to a child so that a new piece of code can reuse and build upon the features of an existing one. JavaScript implements inheritance by using objects. Each object has an internal link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. By definition, null has no prototype and acts as the final link in this prototype chain. It is possible to mutate any member of the prototype chain or even swap out the prototype at runtime, so concepts like static dispatching do not exist in JavaScript.



                  PointedEars
                  --
                  var bugRiddenCrashP ronePieceOfJunk = (
                  navigator.userA gent.indexOf('M SIE 5') != -1
                  && navigator.userA gent.indexOf('M ac') != -1
                  ) // Plone, register_functi on.js:16

                  Comment

                  • David Mark

                    #10
                    Re: Why (new RegExp) type is function not object

                    On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                    wrote:
                    David Mark wrote:
                    On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                    wrote:
                    David Mark wrote:
                    >On Dec 8, 2:55 am, EME <megaupload.sh. ..@gmail.comwro te:
                    >>new RegExp instanceof Function //result false in Firefox
                    >It isn't an instance of Function (it is an instance of RegExp.)
                    It isn't an instance of anything, as that would imply class-based inheritance.
                    >
                    You are kidding right?
                    >
                    I am not.
                    That was a rhetorical question. I know you are serious about being
                    pedantic.
                    >
                    The operator quoted above that sentence should explain why I used that terminology.
                    >
                    The operator above was borrowed from Java, a programming language that
                    uses only class-based inheritance, to ease programming in JavaScript for
                    No kidding.
                    developers that a familiar with Java. However, `instanceof' is only a
                    name, not a hint regarding the underlying concept of the operation in
                    I wasn't taking a hint from it.
                    implementations of Edition 3 of the ECMAScript Language Specification.
                    It is therefore inappropriate to speak of objects as instances of their
                    constructors.
                    Thanks for that.

                    Comment

                    • RobG

                      #11
                      Re: Why (new RegExp) type is function not object

                      On Dec 9, 1:06 am, David Mark <dmark.cins...@ gmail.comwrote:
                      On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                      [...]
                      It is therefore inappropriate to speak of objects as instances of their
                      constructors.
                      >
                      Thanks for that.
                      Maybe the instanceof operator should be "constructedby" ? :-)


                      --
                      Rob

                      Comment

                      • John G Harris

                        #12
                        Re: Why (new RegExp) type is function not object

                        On Sat, 8 Dec 2007 at 14:57:13, in comp.lang.javas cript, Thomas
                        'PointedEars' Lahn wrote:
                        >David Mark wrote:
                        >On Dec 8, 2:55 am, EME <megaupload.sh. ..@gmail.comwro te:
                        >>new RegExp instanceof Function //result false in Firefox
                        >>
                        >It isn't an instance of Function (it is an instance of RegExp.)
                        >
                        >It isn't an instance of anything, as that would imply class-based inheritance.
                        Let's be really pedantic now. "An instance of RegExp" is just short for

                        "The object is a member of the class of all those objects that could
                        possibly be constructed by the function named RegExp".


                        Let's be differently pedantic now. Here is a quote from the ECMAScript
                        standard :

                        "RegExp instances inherit properties" ...


                        John
                        --
                        John Harris

                        Comment

                        • Richard Cornford

                          #13
                          Re: Why (new RegExp) type is function not object

                          RobG wrote:
                          On Dec 9, 1:06 am, David Mark wrote:
                          >On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn wrote:
                          [...]
                          >>It is therefore inappropriate to speak of objects as
                          >>instances of their constructors.
                          >>
                          >Thanks for that.
                          >
                          Maybe the instanceof operator should be "constructedby" ? :-)
                          The - instanceof - operator makes an assertion about the runtime
                          relationship between the objects on an object's prototype chain and the
                          object/value referred to by the - prototype - property of a function at
                          the moment of the operation. Because the - prototype - properties of
                          functions can be assigned values at any time the results of -
                          instanceof - do not necessarily represent anything beyond the outcome of
                          the pertinent algorithms.

                          As usual, if the 'Class' concept has been employed in javascript code
                          design, not violated at runtime, and no attempt has been made to extend
                          that concept across possible multiple frames (so there is only a single
                          instance of each 'constructor') then javascript's - instanceof - can be
                          employed as if it was broadly analogous to Java's - instanceof -.
                          Unfortunately the coincidence of names tends to give people familiar
                          with Java the false impression that the two operators are more related
                          than they actually are (and then they whinge when they find out that the
                          relationship in javascript is much more specific and concrete than the
                          conceptual relationship that is implied in Java).

                          Richard.

                          Comment

                          Working...