A detailed comparison between jquery and the prototype framework

  • 2020-03-29 23:56:37
  • OfStack

I used to use jquery for the interface, but now I use the prototype that comes with rails because I have to use a lot of ajax effects

Since jquery is used a lot, the new framework is the same, but the details are different...

1. Dom loading:

Jquery has a dom ready method, which delays the binding of js functions until the dom tree is complete (without this feature, some bindings such as element's event functions may go wrong) :

The $(document). Ready (function () {});

But prototype doesn't... Have to find their own unofficial extension, inconvenient, this basic function, such an important function, I do not know why the delay to add to the core library

2. Path lookup and dom positioning

Jquery's dom lookup and CSS positioning are consistent, it is very convenient to use, which is one of its highlights and advantages

$(' # func select_all '). Click (function ()
$(this). The parent (' div '). The parent (' div '). The find (' li. The checkbox input: the checkbox ')

Prototype only finds a single dom object for convenience --$(id)

The trouble is to separate the individual from the array, if you look for many objects in a path

Get $$(' div.right_contact '), this style is still to locate a certain type of object

Instead of path-finding, this is not as convenient and conceptually consistent as jquery

3. Function, event binding
For example, when you bind a div with class right_contact to a click highlight event,prototype writes:

$$('div .right_contact').each(function(item){ 
item.observe('click', function(event){ 
new Effect.Highlight(item,{ duration: 2.0,startcolor: '#ffff99',endcolor: '#fffffff',restorecolor: '#fffffff' }); 

If it's jquery, it's much simpler:

$(' right_contact '). Click (function () {     
$(this). ToggleClass (' hilight ');

I've used a lot of frameworks, but the most impressive is a framework called hge game engine, which encapsulates a lot of the low-level details and implementation methods, and he said, You could create everything from a simple puzzle to advanced multilayered platformer or strategy without even thinking of any non-game logic code

A good framework is one that focuses on business logic rather than technical features. Jquery is better than prototype in terms of design patterns. A good example of this is that if you want to click on a trigger function, prototype does an extensive observe method and registers the click event
Jquery has an item.click function... Observe is all inclusive, but with jquery creating special functions specifically for the most common events, it's much easier to focus on the business logic...

Related articles: