|Written by Mike James|
|Monday, 24 January 2022|
Page 2 of 2
In truth prototypes aren't really about inheritance, they are more about implementation efficiency. A prototype provides a packet of methods, i.e. code, that can be shared without duplication between any number of objects.
The object factory, or constructor, provides the mechanism of prototype inheritance. Any object created by an object factory uses the object factory's prototype property in an attempt to find any method or properties it doesn't implement directly. By setting the object factory's prototype property to another object you can implement inheritance and by prototype chaining you can also implement an inheritance hierarchy. This might sound like standard object-oriented inheritance, but it has its dynamic aspects. You can add properties and methods to the prototype object at runtime and so what is inherited can change at runtime.
This is inheritance, but not as we know it.
The key idea, as already mentioned, is that prototypes are not really about inheritance, they are about efficient sharing of code between multiple objects.
Asynchronous programming is the big programming problem that we fail to tackle head on. Languages like Python that come without a standard user interface don’t naturally encounter the async problem and mostly it doesn’t make an appearance in the language until much later – it isn’t a core issue.
A Functional Language
You can argue that having functions as first class objects is actually against the functional programming idea because it allows yet another way for functions to record state information. However, it might also be said that having functions as objects provides additional opportunities above and beyond the restrictions of functional programming.
Now available as a book from your local Amazon.
|Last Updated ( Monday, 24 January 2022 )|