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

Re: changing prototype object

Expand Messages
  • pauanyu
    No, you can t. You can only set the hidden prototype at creation. Some implementations (such as Chrome and Firefox) give programmers access to the __proto__
    Message 1 of 2 , Oct 13, 2010
    • 0 Attachment
      No, you can't. You can only set the hidden prototype at creation.

      Some implementations (such as Chrome and Firefox) give programmers access to the "__proto__" property, which both tells you what the prototype is, and lets you change it.

      However, this magical property is not available in some implementations (it's probably not in IE, for instance), so doing this in a cross-browser manner is not possible.

      However, if you're writing a specialized program (for example a Chrome/Firefox extension), then try using the __proto__ property.

      --- In jslint_com@yahoogroups.com, Mark Volkmann <r.mark.volkmann@...> wrote:
      >
      > Suppose I do the following things:
      > - write a constructor function
      > - set the prototype property of my constructor function to refer to
      > another object
      > - create an object using the new operator on this constructor function
      >
      > I know that I can now add new properties, including functions, to the
      > prototype of my new object.
      > Is it possible to change the prototype of my new object to refer to a
      > different object,
      > thereby losing the properties of the former prototype object
      > and gaining the properties of the new prototype object?
      >
      > I think the answer is "no".
      > I've written code to test this and it seems that the object always
      > remembers it's original prototype object.
      > However, I haven't been able to find any documentation that says this
      > is what is supposed to happen.
      >
      > --
      > R. Mark Volkmann
      > Object Computing, Inc.
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.