The __proto__ custom property allows you to set up a prototype of an existing object.
In your example, both versions will achieve the same effect, but there is a difference:
Prototype
child1 is the same as the parent prototype, while the child2 prototype is an empty object, and this empty object prototype is the same as the parent prototype.
Of course, like child2 , and its prototype does not have a test method, this method will be discussed later in the prototype chain.
Also consider the following:
You want to create only one object, which should inherit from another object. Now you can write a constructor, but JavaScript has object notation for creating objects directly and you want to use it.
If you have a constructor function, then allowing new objects to inherit from another object is just as easy to configure the prototype of the constructor function on that object.
Obviously, this does not work for object literals. But in Firefox, you can use __proto__ to install it:
var server = { __proto__: connect.HTTPServer.prototype, other: properties };
Since this property is not standard, it should be avoided.
Felix Kling Mar 22 '11 at 22:28 2011-03-22 22:28
source share