Possible Duplicate:
prototype based vs. class based inheritance
This question came up at work the other day – what’s the difference between a class-based language like Python, and a prototype-based language like Javascript? Aside from differing approches, both ways seem very similar and we struggled to find something that a class-based language could do that a prototype-based language couldn’t, or vice-versa.
Can anybody elaborate or go into any detail on how they differ fundamentally?
I haven’t found much online about the differences, just sites that show you how to accomplish one with the other (such as this: Simulating classes with prototypes in JavaScript)
Any enlightenment appreciated!
It seems like you’re familiar with the actual languages, so you know what the difference is, right? I guess you’re asking about the differences at a deeper, maybe more “philosophical”, level.
Class-based languages tend to work from the top down, general to particular. The classic example would be where you define a ‘Vehicle’ class, and then subclasses like ‘Car’, ‘Train’.
A prototype-based language would instead tend to start with the particular, in fact start with an instance of the particular and modify that.
I like this: http://steve-yegge.blogspot.ie/2008/10/universal-design-pattern.html
In the end it’s not a question of if you can do inheritance in JS or whether there is something that you can do in one language but not the other. It’s a deep difference in their ways of approaching problem solving. For a particular problem a good idiomatic solution that made best use of the language’s features would probably be quite different in a prototype-based language from one in a class-based language.