Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mix jQuery with other libraries?

 
Axel Janssen
Ranch Hand
Posts: 2166
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am more a ocasional java script developer. As I understood the debate so far, jQuery is very good for a certain task (traversal of DOM).
Now if in my team, there is relatively much experience with Prototype, is it advisable (or even possible) to mix the 2 libraries?
That means more specifically: Using prototype for ajax stuff and jQuery just for the complexer dom-access bits? Or qualifies mixing prototype and jQuery as a particularly bad idea and jQuery should be used separated from prototype for projects, where more advanced dom access is expected?

regards
Axel
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently using both in a project. Not because I want to but because I had to. Since both libraries use the $ function the only thing you need to do is make sure you tell jQuery to release control of that function by calling:

jQuery.noConflict()

somewhere before all your other scripts run. That will tell jQuery to ignore the $ function so that prototype (or some other library) can use it. Then you just need to use jQuery.foo instead of $.foo for all your jQuery functions.

Personally, I prefer jQuery to prototype for everything; AJAX, DOM traversal. I just really like jQuery's approach to the problem and its extensibility. Granted, I haven't peaked that the very latest prototype release (1.6 I think) but as of 1.5 I believe JQuery to be a much better library.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, jQuery goes out of its way to make sure that it plays well with others.

Unlike most other libraries, its global name incursion is limited to two identifiers: jQuery and $. And as Gregg reported, the latter can be unbound in a supported fashion through a call to $.noConflict(). Now that's friendly!

Also like Gregg, I also find jQuery's Ajax support to be more intuitive and less wordy than Prototype's and use jQuery exclusively for my personal and client projects. In my day job, we use Prototype for a bunch of things and so, like with your project, the two libraries are sometimes used on the same page.

Because of jQuery's non-invasiveness, this is never a problem.
[ January 15, 2008: Message edited by: Bear Bibeault ]
 
Yehuda Katz
Author
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear makes a good point. It would be entirely feasible to use jQuery's Ajax support only while using Prototype's class support alongside it, because jQuery's components are very tightly namespaced:



Keep in mind that if you want to use jQuery's global callbacks for Ajax (such as setting callback functions for *every* Ajax call), though, you'll need to use jQuery exclusively for making Ajax calls.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic