Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery inspired by prototype?

 
Sapna Grover
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks similar to prototype. How would one compare the two?

Thanks
Sapna Grover
 
Daesung Park
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "$" is used to query element in both of them, that makes me think like you. But I don't know which one inspired which one. Anyway, I was little surprised at the fact that "$" can be used as a function name in JavaScipt. It is rare case in other programming languages as far as I know.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything is inspired by something. There are no unique ideas. Protoype an JQuery pretty much try and solve the same problem which is how you make JavaScript pleasant to use. And they both try and make it simpler to do mundane and often times complex things with less typing. Of course, they do much more than that we well.

The largest difference I see between Prototype and Ajax is Prototype feels more like an Object Oriented approach where JQuery feels more like an expression language. Consider this...

Prototype
-----------
new Ajax.Updater(...)

JQuery
-----------
$.load(...)

Both do the exact same thing, more or less. They take the response from an AJAX request and shove it on the page.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aside from the fact that the both use $ as a core function name, and are both JavaScript libraries, they are about as different in approach as you can get.

Prototype took the invasive path of modifying the core objects in JavaScript to make them look more like Ruby. As Gregg pointed out, it uses, and expects its users to use, an object-oriented approach to JavaScript. In addition to modifying the core JavaScript objects, it also adds a lot of names and objects to the global namespace.

jQuery is non-invasive in that it does not modify any JavaScript object. Rather it uses a wrapper to wrap new functionality around elements rather than directly modifying them. It adds only two names to the global namespace: jQuery and $, and the latter can be undefined if you want to use jQuery on the same page as Prototype. jQuery can be used with object-oriented JavaScript or plain functional style JavaScript.

I think both are strong and well-written libraries, and choosing either depends upon which approach you prefer. Personally, I have adopted jQuery for use in all my personal projects as I like its lighter, non-invasive style (and there are tons and tons of jQuery plugins to do just about anything one might need). In my day job, we use both.
[ January 16, 2008: Message edited by: Bear Bibeault ]
 
Yehuda Katz
Author
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jQuery was inspired by a number of things, including Dean Edwards' Base and the original Behaviours library that was written on top of Prototype. John is also friendly

Prototype's primary mission is to make JS more like Ruby; jQuery's primary mission is to make it easier to do DOM Scripting. See other threads from this week for more details.

There's a lot of jQuery's approach that has been adopted by Prototype. Most notably their revamped event system looks a lot like jQuery's event system. Then again, pretty much everyone has come on board with things like full CSS3 selectors and simplified events.

For an interesting historical perspective, check out John's initial post where he talked about the ideas that would eventually become jQuery: http://ejohn.org/blog/selectors-in-javascript/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic