Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Object: proto

From MDC

Non-standard

Contents

[edit] Summary

Points to the object which was used as prototype when the object was instantiated.

[edit] Syntax

obj.__proto__

[edit] Description

When an instance of an object is created, its __proto__ property is set to the .prototype. E.g. var fred = new Employee(); does fred.__proto__ = Employee.prototype;.

This is used at runtime to look up properties which are not declared in the object directly. E.g. when fred.doSomething() is executed and fred does not contain a doSomething, fred.__proto__ is checked, which points to Employee.prototype, which contains a doSomething, i.e. fred.__proto__.doSomething() is invoked.

[edit] Example

function extend(child, supertype)
{
   child.prototype.__proto__ = supertype.prototype;
}

extend(Animal, Lifeform);
extend(Plant, Lifeform);