JavaScript is a prototype language. To turn it into a class based language adds little value? I am not talking about best-practice here. I remember reading an article from way back, which claimed that the class-based worldview is perceivably more flawed than the one of prototypes. My summary can be found here: http://carnotaurus.tumblr.com/post/3248631891/class-based-javascript-or-not. I am resisting to use the class-based jQuery add-on and other attempts at faciliating class-based JavaScript. Peer pressure is strong but is there a stronger theoretical or practical reason why I should stop resisting?
|
migrated from stackoverflow.com Feb 15 '11 at 22:03
Continue to resist!JavaScript is fine as is, it just suffers from a few misunderstandings.
|
|||
|
Recently I discovered the reasoning behind prototype based versus class based object oriented languages. I always thought that prototypes make no sense, because sooner or later you will find out your objects are in some way similar and you can group them, create hierarchies and use polymorphism... I think the point is to understand, that with prototypes, the language itself is more flexible - you could for instance implement contracts, aspect oriented programming and all sorts of metaprogramming much easier. You could create smarter interfaces, components with dependency resolution and much more... I think prorotypes are a bettter language feature, but one has to remember, that classes are needed and there should be a library for them. |
|||
|
You shouldn't care whether your JavaScript is class based or prototype based. The important question is how to make your program object oriented. Since the DOM plays the central role in websites/web-applications you could focus on making the DOM nodes object oriented instead. See for example this demo (implemented using the Entwine library): |
|||||||||||||||
|