We recently built a web app using Prototype, making a fair amount of use of its Class.Create() functionality. Right now, we're considering migrating to jQuery as it seems to be considered a 'better' library. I've been doing some reading on the topic and found out that jQuery does not have straightforward built-in support for class-creation like Prototype does. Of course, there's still the .prototype and the jQuery.extend (as mentioned in https://stackoverflow.com/questions/79477/how-to-create-an-object-oriented-class-in-jquery), but after some more searching, I got the feeling that jQuery doesn't really 'want' you to script this way...
The same page has a post mentioning John Resig's Classy plugin, which looked great to me. However, the page states that it was actually an April Fools Day joke, and that Resig actually advises not to use the code. I'm happy to oblige, but I'd like to understand what the reason for all this is, and, of course, what it is they DO want you to do instead. Can someone enlighten me?
-edit-
Thanks for the interesting answers. For the sake of clarity: does this mean it is fine to rewrite the classes I made in Prototype to the jQuery way of 'shaping' a class, and still use them in the same 'manner' as before? Or is this still considered bad practice, and should I use a different approach?
First crappy Google search for "object oriented javascript" turned this up...but it explains the point I wanted to get across:
JavaScript Object-Oriented Programming
Just take a look at the first paragraph and you find:
Javascript isn't a fully Object Oriented programming language. The use of classes in JS is based on the prototype functionality. The Prototype library masks the use of the prototype functionality to create your class. jQuery expects you to use the prototype functionality the same way you would using regular JS to extend jQuery itself and create your own custom objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With