The function prototype

Each function has a prototype property that by default points to an empty instance Object (called: prototype Object).

Within each prototype object there is a constructor, which points to the function object

fn.prototype.constructor === fn // true

Add attributes (usually methods) to the prototype object ===> the instance object can access

Action: All instance objects of a function automatically have properties (methods) in the stereotype

Explicit and implicit archetypes

Each function has an explicit prototype that by default points to an empty Object instance

Each instance object has a __proto__, or implicit prototype

The implicit stereotype of an object is the value of the explicit stereotype of its corresponding constructor

Fn.prototype === fn.__proto__

The __proto__ attribute is automatically added when an instance object is created using new

Prototype chain

When accessing a property

  • First look in their own properties, find the return
  • If not, look up the __proto__ chain and return
  • If not found, return undefined

Function: Find the end of the attribute prototype chain of an Object: Object.prototype.

All objects inherit properties from Object.prototype