• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mix jQuery with other libraries?

 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic