Image Image Image Image Image

© Copyright 2012 ABCoder | Email | RSS

Scroll to Top

To Top

jQuery

10

May
2009

6 Comments

In jQuery

By abcoder

jQuery vs. prototype.js

On 10, May 2009 | 6 Comments | In jQuery | By abcoder

I’m basically a jQuery developer. I had little knowledge about prototype.js. All I knew is jQuery is better than prototype, so I never got interested about it.

However, for some reason I started a project with prototype.js and each line of code makes it clearer that which one is better. Somehow I finished the project using prototype.js along with scriptaculous.js and effects.js. Everything was fine in IE7 and FF 3. But it breaks in IE6. I was not happy with the unnecessary huge code. For example there is no live event in prototype.js, you can not apply an event to a group of elements with same class (You have to use loop for it), there is nothing like jQuery.animate function by which you can do any css animation (You have to add scriptaculous.js for some pre-built animation effects!) and a lot more limitations.

Even the scriptaculous.js is not that rich, for example using ScrollTo effect you can smoothly scroll to any anchor tag “vertically” only but no way of ScrollTo horizontally(!) in case your page is landscape orianted. Here is the code that I used instead(I found the idea from the source code of ScrollTo function):

var scrollOffsets = document.viewport.getScrollOffsets();
var elementOffsets = $$('div.active ul li')[index].cumulativeOffset();
new Effect.Tween(null,scrollOffsets.left,elementOffsets[0] - lo,function(p){window.scrollTo(p,scrollOffsets.top);});

The equivalend jQuery code is:

$("html,body").animate({
scrollLeft: ($('div.active ul li').eq(index).offset().left - leftOffset) + 'px'
}, "slow", "swing");

There are a lot more examples like this. The summary is the code using prototype.js was 180 lines and the equivalent code using jQuery is now only 160 lines + a lot of mental relief that it would work on all browsers :)

One thing I want to make clear is I have no intention to boost anything. In fact both of them are free.

Tags | , , , , , , , , ,

Comments

  1. sector

    jQuery selectors may be better, and slightly less code comparing to Prototype. But Prototype provides OOP, one can write base classes, then extend those, adding new and overwriting existing methods. You just “tried” using Prototype without understanding its power. For huge projects Prototype suits much better than other frameworks.

  2. nahum

    man use scripty2 is next generation of scriptacolous and I think is more about you are in kind of comfort with jquery but prototype has amazing tools like a real HASH that can help really really in a big project with a lot of data, of course if you are building a web page with 5 information sections this don’t help a lot but put in mind that prototype have a little different scope than jquery have. I dont think any is better just difference but try new prototype 1.7 and http://scripty2.com/

  3. hey sector. jquery can be extended just as well as scriptaculous using the jQuery,extend functionality all i find from scriptaculous is buggy animations such as double clicking an element while in the process of an animation screws up the original placement/size of the element as where jquery does not when i see scriptaculous i see more of a “rushed” library containing a lot of “rushed” functionality versus a “well thought out, well written” library such as jquery and as mentioned scriptaculous has some issues with some browser versions. again where jquery does not(as to my current knowledge) just my 2 cents

  4. by scriptaculous i mean prototype INCLUDING scriptaculous. just to clerify

  5. After I discovered jQuery OOP, I switched from Prototype into jQuery. It is simply amazing. There are tons of free jQuery plugins (decent Prototype plugins are not free), Theme Roller, selector chaining, smooth animations and jQuery UI. It took me 2 months to rewrite my Prototype into jQuery and now I have 80% less javascript code, which is very clean and readable. Thanks to jQuery, very well written framework with a lot of functionality. Reading its tutorial for me was enough to get started.

  6. http://madrobby.github.com/scriptaculous/effect-morph/

    This effect changes the CSS properties of an element.

Submit a Comment