Furthermore, for prototypal inheritance you won’t need the strange (class-like) prototype of a function. You inherit from any object, much like the first example of inheritance I used in my previous article. To refresh your memory, here it is again.
By changing the object’s internal prototype (i.e. its parent) to
Person it inherits all of its attributes. This is prototypal inheritance.
new operator). But as a prototype-based programming language it is somewhat awkward to lack prototypal inheritance. Back in 2006 Douglas Crockford wrote an article about this.
His article manifested itself into the core language as the
Object.create function. Taking the above example you can make a copy of
Person using this function.
The object is identical to the one in the former example and nearly identical to an object created using a constructor.
I.e. the following statements would be true given that
Person is a constructor function and that
Person is the object from the first example respectively.
Browser support for prototypal inheritance is pretty good, meaning that Internet Explorer is last of the major browsers to support it (as of version 10). The
Object, which obviously is one of the major advantages of using a dynamic language.
new keyword and constructor functions. How does prototypal inheritance relate to that? There one way really to find that out and that would be by testing it.
new keyword for years. What surprised me was that this assumption failed for Firefox. It’s also interesting to see how different browsers relate to others, performance wise.
To get a decent overall view it is of course important to get a wide range of different browsers and operating systems. So please run the performance tests on all your browsers, it only takes a few seconds.
So now what?