Day 69 JavaScript Object.Create > Function Constructors

As we learned from last blog function constructors was a method to create objects mimicking other languages. Other languages cannot take advantage of prototypical inheritance. This method fully utilizes the JavaScript engine instead of trying to mimic other languages.

Pure prototypical inheritance is a powerful way to take advantage of JavaScript dynamic typing. Another way to create objects is called object.create.

This is all about creating objects and changing how to construct them. By creating an object then creating a new object you can pass it from the previous object. This will set the prototype as the previous object for the new object.

Object.create creates an empty object with its prototype pointing at the previous object. You can override whatever you want to by adding properties and methods you want to on the created object. You just simply add the same name as the original objects property or method on the new object.

Since the JavaScript engine travels down the prototype chain looking for a property or method it’ll see the new property or method and not move down the chain.

That’s the power of pure prototypical inheritance. You simply make objects and create new objects from them pointing to other objects as their prototype.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up ↑

%d bloggers like this: