Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__proto__ for IE9 or IE10

Is there any possibility to change the __proto__ property of an object in IE9 or IE10? Or is MS still not planning to include it in their JS engine?

I need it in a very special situation where I need to change __proto__ after the object is created.

like image 579
Van Coding Avatar asked Dec 07 '11 10:12

Van Coding


People also ask

Is __ proto __ deprecated?

__proto__ is considered outdated and somewhat deprecated (moved to the so-called “Annex B” of the JavaScript standard, meant for browsers only). The modern methods to get/set a prototype are: Object.

What does __ proto __ in an object is pointing to?

It is the prototype of objects constructed by that function. __proto__ is an internal property of an object, pointing to its prototype.

What is the use of __ proto __ in JavaScript?

__proto__ is a way to inherit properties from an object in JavaScript. __proto__ a property of Object. prototype is an accessor property that exposes the [[Prototype]] of the object through which it is accessed.

Is __ proto __ a property?

The __proto__ property of Object. prototype is an accessor property (a getter function and a setter function) that exposes the internal [[Prototype]] (either an object or null ) of the object through which it is accessed.


3 Answers

__proto__ is going to be standardized in ES6. It is currently in Appendix B of the ES6 draft which in practice means that if it is implemented it needs to have the following semantics.

__proto__ is both available as an accessor on Object.prototype which means that all objects can read and write it by default. However, it can be removed from Object.prototype (using delete). Once deleted __proto__ will work as a normal data property with no side effects on setting.

__proto__ is also a special syntactic form in object literals. It will work to set the [[Prototype]] even if Object.prototype.__proto__ was deleted.

var p = {a: 1};
var o = {
  __proto__: p,
  b: 2
}

ES6 also introduces Object.setPrototypeOf (not in the appendix). This is preferred over setting __proto__.

__proto__ is available in all modern browsers, including Internet Explorer 11.

like image 160
Erik Arvidsson Avatar answered Oct 21 '22 02:10

Erik Arvidsson


__proto__ is included in IE11 found in the leaked build of Windows Blue: http://fremycompany.com/BG/2013/Internet-Explorer-11-rsquo-s-leaked-build-395/

like image 35
David Storey Avatar answered Oct 21 '22 02:10

David Storey


A nonanswer as a last case resort:

Change your code so that all the properties that would originally be accessed via the changed prototype are now accessed via explicit delegation over a normal property:

{
   a: 17,
   __proto__: { ... }
}

to

{
   a: 17,
   proto: {...}
}
like image 42
hugomg Avatar answered Oct 21 '22 04:10

hugomg