1. What is a prototype?

In JavaScript, a prototype is a Prototype object that represents relationships between types.

The purpose of a stereotype object is to store shared methods and properties for each instance object, and it is just a generic object. And all powers share the same stereotype object, so there is only one copy of the stereotype object, as opposed to instance methods or attributes.

Every object has a stereotype (except null and undefined), which can be understood as the object’s default properties and methods.

2. What is a prototype chain?

JavaScript has only one structure: objects. Each instance Object has a private attribute (called __proto__) pointing to its constructor’s prototype Object. The prototype object also has a prototype object of its own (PROTO), cascading up until an object’s prototype object is null.

Access path:

  • If null is not found, undefined is returned
  • Object.prototype.ptoto === null
  • All methods that are executed from prototypes or higher, where this, when executed, refers to the object that is currently firing the event