I am trying to reconcile this statement with the understanding that the prototype is a property related to the parent type, since this is achieved by inheritance.
Not. The prototype relation to another object (from which the properties are inherited) is carried out through an invisible link, sometimes referred to as [[prototype]] .
The actual existing existing .prototype property in the constructor function is the object from which all instances that were built by this function are inherited.
So, the prototype chain (inheritance) of the Array object looks like this:
null ^ | Object.prototype ---> {hasOwnProperty(), β¦} // all objects inherit these ^ | Array.prototype ----> {map(), indexOf(), β¦} // all arrays inherit these ^ | {length, 0, 1, 2, β¦} // an example array // as if constructed by new Array(5) or [42, 7, 6]
Why do some methods have .prototype and some not?
Functions available in .prototype will be inherited by all instances, you can call them directly on them if they were their method.
Functions that are placed directly above the constructor function, such as Array.isArray or Array.of , are not associated with the instance and, therefore, are βstaticβ. You call them mainly with non-arrays as arguments.
Bergi
source share