Home  >  Article  >  Web Front-end  >  Detailed comparison between jquery and prototype framework_jquery

Detailed comparison between jquery and prototype framework_jquery

WBOY
WBOYOriginal
2016-05-16 17:13:25793browse

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

Because jquery is used a lot, it will be similar to another framework, but there are many differences in details. . .

1.dom loading:

Jquery has a dom ready method, which postpones the binding of js functions until the dom tree is completed (without this function, binding of some element event functions and the like may go wrong):

$(document).ready(function(){});

But there is no prototype. . . I have to find unofficial extensions myself, which is inconvenient. I don’t know why this basic function, such an important function, has not been added to the core library for so long

2.path search, dom positioning

JQuery’s DOM search is consistent with CSS positioning, and it feels very convenient after using it. This is one of its highlights and advantages

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

Prototype is only convenient for finding a single DOM object--$(id)

The more troublesome thing is to separate the individual and the array. If you find many objects under a path

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

Instead of using path search, this aspect is not as convenient and consistent as jquery

3. Function, event binding
For example, bind the click highlight event to a div with class right_contact. The prototype is written as:

Copy code The code is as follows:

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

If it is jquery, it is much simpler:

$('.right_contact').click(function(){ 
$(this).toggleClass('hilight');
})

I have used many frameworks, and the most impressive one is a framework called hge game engine, which encapsulates a lot of underlying details and implementation methods. Then 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

An excellent framework should focus attention on business logic rather than technical features. In terms of design patterns, jquery is better than prototype. The most typical example is that if you want to trigger a function by mouse click, prototype should be large and comprehensive. The observe method, and then register the click event
and jquery has the item.click function. . . Observe is all-encompassing, but jquery's practice of creating dedicated functions for the most commonly used events allows people to focus more on business logic. . .

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn