|
|
|
|
|
by olavk
5499 days ago
|
|
Very few examples of prototypal inheritance shows it beeing practically different from class based inheritance. If all (non-function) instance fields are assigned new values - like the Point example in the article - it is basically the same. Prototypal inheritance makes a difference if one instance inherits field values (other than functions) from another instance. But this does not seem to be very common. I believe one of the original use cases for prototypal inheritance were to save memory by letting GUI controls share common properties. Eg. if you had 10 buttons on the screen which all had the same color, same dimensions etc. With class based inheritance each instance would have their own copy of all properties, even if they have the same values in each instance. I don't think that kind of optimization is relevant in modern JavaScript. |
|