Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the current differences between jQuery and Prototype? [closed]

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

like image 554
Daemin Avatar asked Jan 14 '10 13:01

Daemin


People also ask

Is jQuery still being updated?

In this world of JS frameworks, native JS will always have its place and JQuery is something closest to native Javascripts. Its same about does server side programming is still relevant since now there is node. So for me yes, JQuery is still relevant. Is jQuery still relevant in 2022?

Is jQuery still supported?

jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of Aug 2022, jQuery is used by 77% of the 10 million most popular websites.


2 Answers

Previous discussion

Much, if not all of your question has been discussed already. See the search or:

  • How would you go about for switching a site from Prototype to jQuery
  • Prototype, dojo or jQuery?
  • Why does everyone like jQuery more than prototype/script.aclo.us or mootools or whatever?
  • Is it true that Jquery + Rails is problematic?
  • Using jquery in Rails

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.

like image 115
Pekka Avatar answered Sep 19 '22 15:09

Pekka


Pekka's answer is great, but one thing that should be added is that Rails is moving heavily in the direction of being Javascript framework agnostic. Although when Rails first came out, its AJAX integration was innovative, the Javascript landscape has changed dramatically since then, and the Rails integration doesn't really live up to best practices anymore. As such, the Prototype integration should not be considered a major factor today on Rails 2.3, and it will be even less of a factor in Rails 3.0 which will likely be released within the next few months. I recently read an interesting article describing some of the most significant changes to Rails' Javascript integration in years.

My current project has thousands of lines of legacy Prototype code, but we've recently started using jQuery because its benefits were too great to pass up. My impressions:

Prototype is a mature framework that does a very good job shoring up browser differences and providing very well-rounded functionality. Unfortunately it is a bit heavy-handed with its changes to the default Javascript environment, and it's not seeing rapid development and doesn't have a significant plugin ecosystem.

jQuery is a newer framework that was able to leverage some of the lessons of the early javascript frameworks like Prototype to create something more modular, less obtrusive, and significantly more powerful and concise. I still love Prototype, but jQuery's DOM manipulation and plugin ecosystem is just too good to ignore anymore. If I was starting a greenfield project I'd have to go with jQuery because that seems to be where the innovation is happening (at least between those two choices).

like image 21
gtd Avatar answered Sep 21 '22 15:09

gtd