javascript.eval(object.prototype)

Francis Pham
1 min readSep 19, 2015

--

A prototype is a singleton object for each class that: contains the current class’ methods, has a public reference (.constructor) to the constructor function to make objects of the current class, and a private reference (passed in at Object.create) to the superclass’ prototype. Since prototype is a Class property, the instance property is __proto__, but getPrototypeOf should be used:

Class.prototype === [[prototype]] === Object.getPrototypeOf(obj) === obj.__proto__

prototype.constructor is the Function that creates objects of the current class. The base object is Object, which does not have a prototype.

IMPORTANT: if the object is an instance, call Object.getPrototypeOf(obj) to get the prototype, NOT instance.prototype since prototype is a CLASS property; instance.__proto__ is possible, but it’s much slower & not recommended.

Instance properties or methods will override the prototype’s properties or methods of the same name because the constructor bindings occur AFTER the prototype bindings.

--

--