Loading ...
Sorry, an error occurred while loading the content.

Re: [jslint] Re: top of inheritance chain

Expand Messages
  • Mark Volkmann
    ... Thanks for explaining that! I think I ve almost connected all the dots. function Foo() {} var foo = new Foo(); All of these line print true in Rhino:
    Message 1 of 8 , Aug 1, 2010
    • 0 Attachment
      On Fri, Jul 30, 2010 at 3:49 PM, Douglas Crockford <douglas@...>wrote:

      > > Can someone explain why the second line below outputs false?
      > > I thought since the first line outputs true, the second would also.
      > >
      > > print(Object.prototype.isPrototypeOf(String.prototype)); // true
      > > print(String.prototype.prototype === Object.prototype); // false; Why?
      >
      > prototype is a property of a constructor function, it is not the property
      > through which an object delegates to another object, which is the key to
      > inheritance. In some implementations, the delegation property is surfaced as
      > __proto__, which is distinct from prototype.
      >

      Thanks for explaining that! I think I've almost connected all the dots.

      function Foo() {}
      var foo = new Foo();

      All of these line print "true" in Rhino:

      print(foo.constructor === Foo);
      print(Foo.constructor === Function);
      print(Function.prototype.isPrototypeOf(Foo));
      print(Object.prototype.isPrototypeOf(Function.prototype));
      print(Foo.constructor.prototype === Function.prototype);

      Can someone explain why the last two lines print "false"?

      print(Function.constructor.prototype === Object.prototype);
      print(Function.constructor === Object);

      Maybe my assumption that all function objects inherit from Object.prototype
      is wrong.

      --
      R. Mark Volkmann
      Object Computing, Inc.


      [Non-text portions of this message have been removed]
    • pauanyu
      ... I dunno about Rhino, but in Chrome, Function.constructor.prototype is actually a function, that is constructed by Function. Try this:
      Message 2 of 8 , Aug 2, 2010
      • 0 Attachment
        > print(Function.constructor.prototype === Object.prototype);

        I dunno about Rhino, but in Chrome, Function.constructor.prototype is actually a function, that is constructed by Function.

        Try this:

        print(Function.constructor === Function.constructor.prototype.constructor);


        > print(Function.constructor === Object);

        At least in Chrome, Function's constructor is Function. Fun bit of recursion.

        Try this:

        print(Function.constructor === Function);


        I have no clue how the JavaScript interpreter handles that kind of infinite recursion, but it does.

        --- In jslint_com@yahoogroups.com, Mark Volkmann <r.mark.volkmann@...> wrote:
        >
        > On Fri, Jul 30, 2010 at 3:49 PM, Douglas Crockford <douglas@...>wrote:
        >
        > > > Can someone explain why the second line below outputs false?
        > > > I thought since the first line outputs true, the second would also.
        > > >
        > > > print(Object.prototype.isPrototypeOf(String.prototype)); // true
        > > > print(String.prototype.prototype === Object.prototype); // false; Why?
        > >
        > > prototype is a property of a constructor function, it is not the property
        > > through which an object delegates to another object, which is the key to
        > > inheritance. In some implementations, the delegation property is surfaced as
        > > __proto__, which is distinct from prototype.
        > >
        >
        > Thanks for explaining that! I think I've almost connected all the dots.
        >
        > function Foo() {}
        > var foo = new Foo();
        >
        > All of these line print "true" in Rhino:
        >
        > print(foo.constructor === Foo);
        > print(Foo.constructor === Function);
        > print(Function.prototype.isPrototypeOf(Foo));
        > print(Object.prototype.isPrototypeOf(Function.prototype));
        > print(Foo.constructor.prototype === Function.prototype);
        >
        > Can someone explain why the last two lines print "false"?
        >
        > print(Function.constructor.prototype === Object.prototype);
        > print(Function.constructor === Object);
        >
        > Maybe my assumption that all function objects inherit from Object.prototype
        > is wrong.
        >
        > --
        > R. Mark Volkmann
        > Object Computing, Inc.
        >
        >
        > [Non-text portions of this message have been removed]
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.