0

In IE you can't use obj.__proto__ = some_proto, but you can go around this deficit by using inheritance through function, e.g.:

func = function(){}
func.prototype = proto
obj = new func

The problem with this roundabout is that old references to obj are lost and won't point to the new obj with proto as prototype. Is there anyway to change the prototype of existing objects in IE?

JussiR
  • 2,055
  • 3
  • 21
  • 23
  • 1
    No. `__proto__` is just a hack (it's non-standard) and you should never use it anyway. It is currently not possible in JS to change the prototype of an existing object. *related*: http://stackoverflow.com/q/13235313/218196, http://stackoverflow.com/a/7223353/218196 – Felix Kling Feb 04 '13 at 14:27
  • @FelixKling: Make it an answer – Bergi Feb 04 '13 at 14:47
  • Yea, i was guessing it probably isn't, but just wanted to be sure. Thanks for the links! – JussiR Feb 04 '13 at 14:48

2 Answers2

2

No, there isn't.

__proto__ is just a hack and you should never use it anyway (it's not a standard feature). It is currently not possible in JS to change the prototype of an existing object.

Related questions/answers: Changing prototype of an object which was created with literal initialization, https://stackoverflow.com/a/7223353/218196

Community
  • 1
  • 1
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

To answer my own question, IE 11 supports the new Object.setPrototypeOf method. To be use with caution. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf

JussiR
  • 2,055
  • 3
  • 21
  • 23