I’ve been building a Ruby on Rails site in recent months and I’ve only used a small amount of built in JavaScript functions. However I will be doing much more JavaScript development in the coming weeks and months and I am debating on which JavaScript framework to go with.
On the one hand jQuery seems to be the more popular one, but then again Prototype is already built into Rails. I’ve also read a bunch of articles online from a few years ago talking about how jQuery is more concise at some things but sloppy on others, and giving various other opinions.
So my questions are to the people who have used both (preferably recently):
- What is the difference in using either Prototype and jQuery from a pure JavaScript and from a Ruby on Rails perspective?
- Is there a significant difference between them or are they now pretty close to each other in terms of functionality and code writing?
- How high is the switching cost in terms of things that have to be relearnt and code that has to be rewritten?
Thanks
Previous discussion
Much, if not all of your question has been discussed already. See the search or:
Switching from Prototype to JQuery
I’m in the process of switching from Protoype to JQuery, mainly for reasons of performance (I have seen too many benchmarks with Prototype always coming in last to JQuery, MooTools and Dojo.) I would say switching cost is not horrible, because most basic concepts (Selection, Effects, Ajax) are very similar. However, every line of Prototype code has to be carefully rewritten – carefully especially because many helper functions and constructs (
$$$) look deceivingly similar.If your code contains many complex chained constructs that may be available in Jquery as well, but function differently, migration can become a very cumbersome task. If you use it only for quick $() element selection, effects and a bit of Ajax, not so much.
Either way, be prepared for a phase of intense learning. JQuery constructs are small and smart, but are terrible to read IMHO (and look god-awful compared to a block of native Javascript, but that’s a different discussion). It definitely takes time to get familiar with the syntax and principles if you’re coming from a different framework, or native Javascript.