Detailed comparison between jquery and prototype frameworks

Source: Internet
Author: User

Previously, jquery was used for the interface. Now, we use the prototype that comes with rails because of the many ajax effects.

Because jquery is used more often, it is similar to changing a framework, but there are many differences in details...

1. dom loading:

Jquery has the dom ready method, which delays the binding of js functions to know that the dom tree is complete (if this function is not available, binding of some element event functions and other functions may fail ):

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

But prototype does not exist... You have to find unofficial extensions by yourself, which is inconvenient. This basic function, such an important function, does not know why it is not added to the core library.

2. path search, dom Positioning

Jquery's dom search is consistent with css positioning, and it is very convenient to use it. This is a highlight and advantage of jquery.

$ ('. 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)

It is troublesome to separate a single object from an array. If you find many objects in a path

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

Instead of using path search, it is not as convenient and conceptual as jquery.

3. function, event binding
For example, bind the div of the class right_contact to the click highlight event. The prototype is written as follows:
Copy codeThe 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:' # fffffff', restorecolor: '# fffffff '});
});
});

Jquery is much more concise:

$ ('. Right_contact'). click (function (){
$ (This). toggleClass ('hilight ');
})

I have used many frameworks. What impressed me most is the hge game engine framework, which encapsulates a lot of underlying details and implementation methods. Then, he said: you cocould create everything from a simple puzzle to advanced multilayered platformer or strategy without even thinking of any non game logic code

A good framework should focus on business logic rather than technical features. In terms of design patterns, jquery is superior to prototype. The most typical example is to trigger a function by clicking the mouse, prototype implements a big and comprehensive observe method, and then registers the click event.
Jquery has the item. click function... Observe is inclusive, but jquery, a special method of creating a proprietary function for the most common events, can make people focus more on the business logic...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.