concat() method on Mozilla, we'll actually discover that there are two different
We are familiar with strings and we will begin learning about arrays in the next lesson.
According to the Mozilla documentation:
This is really all you need to know for now. Prototypes are just a way for an object to inherit functionality from another object.
When we refer to
String.prototype.concat(), we are referring to a
concat() method that all strings inherit. When we say
Array.prototype.concat(), we are referring to a
concat() method that all arrays inherit. Even though these methods have the same name, they are actually different methods. Sure, they do essentially the same thing: they put things together. When called on strings, they put two strings together. When called on arrays, they add something to the end of the array.
How do arrays or strings know how to
So let's reiterate what we do need to know. We'll often see
prototype in the following context:
Array.prototype.join(). In this case,
prototype refers to a method that can be called on a type of object. This is relevant because we are about to add a different kind of object to our toolbox - arrays - and we need to be clear that arrays have a different set of methods than strings and other objects, even though these methods sometimes have the same names.
Array.prototype.join(). We want to make sure you're not confused when we start doing this. It's just a way to make things clearer.
And if you really have to look into prototypal inheritance more to get a grasp on all of this, see the Mozilla documentation on Object prototypes.
Lesson 3 of 31
Last updated June 22, 2020