Re:Refactoring Legacy JavaScript Code to Use Classes
by cmrdporcupine on Tuesday March 07, 2017 @08:12PM
(#13816933)
Well arguably the definition of inheritance there doesn't meet the poster's idea of inheritance. Prototype 'inheritance' is a kind of delegation and some prototype OO languages make that explicit by using different terminology (Self says 'delegate' and not 'parent' for example).
But then arguably in class-based OO languages, classes don't "inherit" either and really just delegate to other classes.
(FWIW I wrote a big chunk of the prototype-OO article on WP at one point. Not sure how much of that text still exists)
Re:Refactoring Legacy JavaScript Code to Use Classes
by tchaffee on Tuesday March 07, 2017 @10:20PM
(#13817588)
It's sort of wrong, but not really if we are using the commonly used definition of inheritance where we think of the strict hierarchical inheritance provided by classes. And you mention prototype delegation which is only one type of inheritance provided by javascript and is also hierarchical. There are two other types of inheritance you can use with javascript: functional inheritance, and concatenative inheritance. Concatenative inheritance is so different from class inheritance that most people don't even call it inheritance. They call it object composition. Which has been preferred over class inheritance as far back as the GoF "Favor object composition over class inheritance." More here: https://medium.com/javascript-scene/master-the-javascript-in...
That is 100% wrong. Prototypes are inheritance. Quoting from wikipedia:
"Prototype-based programming is a style of object-oriented programming in which behaviour reuse (known as inheritance) is performed via a process of reusing existing objects via delegation that serve as prototypes."
I have no idea what you were trying to say, but what you wrote is nonsense.