Design-patterns
The main difference with Constructor is that methods nor properties wouldn’t be storage, copy, at every instance of the new object, if methods and props are assigned to prototype properly. An advantage could be that you will use, with this pattern, less space in memory.
Add some changes to original code
Now you can see your function… not only that
Building our first example:
This class will be added to all objects that we eventually create with JS, it’ll extends Object’s class. In this case log method was added to prototype and that’ll be equal to a function (do NOT use fat arrow function here). ‘This’ at the console references to Object. X being our new object.
Building second example:
At this point, we clearly see that String is inheriting from Object class. Here the regular expression was added to erase space at the beginning and the end, in the case if .trim does not run at the browser, because is not supported in some versions.