It throws me off because I am not sure where the word prototype comes into the mix. What does that mean? Why not just String Methods? or String.method?
I suppose this has always been my issue when looking at docs is that I get there, and there is extra stuff I don’t understand. More than what is being explained in tutorials.
Objects all have a constructor, or class, which has its own methods, but also methods that it affords to all members, or instances.
Objects do not inherit from Object. To call its methods we must use the Object context. Every constructor/class has a prototype that defines the inherited attributes for each instance. In most cases, these attributes are methods.
JavaScript looks for methods on the prototype chain. Every object has a prototype chain by which to access methods. Everything traces back to the parent object, Object. It is the last objective link in the chain. After that there is only null.
The top of the prototype chain is, null. After that it is Object.prototype. After that we begin to split off new special or custom objects which each have their own prototype.
We inherit the charAt() method from String.prototype. We are however carrying out that method on the string object itself. Since its object type has inherited the method from String.prototype we already have an instance of the method without referring to it along the prototype chain. We can access it directly on the instance (context).
Hello, what is up with the Mozilla Documentation because when I looked up for “trim()” is states that one should do “String.prototype.trim()”, what is “prototype”?