The best thing about jquery is API design

Source: Internet
Author: User
Tags query mootools

JQuery will soon release the 1.4 official version, and the code has migrated from Googlecode to GitHub. JQuery is the first JS class library I contacted, as the saying goes, first love is always difficult to forget. A year ago, this difficult to forget is only a pure feeling, can not say the specific reasons. A few days ago again looked over the GitHub on the source. From a purely functional point of view, JQuery is not a particularly good place. What is it that makes me so reluctant?

Yesterday, when I set up taskspeed to check JQuery's test code, I suddenly knew a secret that everyone had known:

One of the best and most reluctant of JQuery is its API design.

For example, the Dom-style API, YUI3 and MooTools frameworks adopt the traditional approach:

El.setstyle (prop, Val);
El.getstyle (prop);
El.setstyles ({Propa:vala, propb:valb});
El.getstyles (Propa, PROPB); MooTools Support

In JQuery, a CSS approach is all done:

EL.CSS (prop); Represents GetStyle
El.css (prop, Val);//Represents SetStyle
el.css ({propa:vala, PROPB, valb});//Represents setstyles el.css
( Prop, Func); Func is a function that returns the Val value

In contrast to these two API designs, JQuery looks less "standard" at first glance. But from the memory and flexibility, I think the jQuery design is more humane. The JQuery API also conforms to the incremental thinking of learning: First learn the simplest case el.css (prop), then understand that there are two parameters, and then find that the parameter can be a map, and further find that Val can also be a function. Func parameters can even bring the learner a surprise: it can also be used like this! JQuery brings a kind of gradual and joyful into the process of learning and using, really beautiful!

The YUI3 API lacks this kind of fun. Query the JQuery API, there is a secret to explore the feeling of treasure. YUI's document query makes people feel is a job, a little boring.

Compared to YUI2, the YUI3 API has made some changes. In YUI2, YAHOO.util.Dom's method name, strictly with the verb beginning, although some method name is long point, but the overall regularity is very strong, the memory is also good. In YUI3, there are Byid, Elementbyaxis and other ways of naming. Just to save a few characters? This inconsistency is puzzling. There are also some ways to name nouns: ancestor, docheight, which is hard to think of as a method at first sight.

Wife said, to sleep, no code words. Finally said: YUI3 API Overall is quite good, such as Node method named, very rigorous. Ancestor is also to correspond to next, prev and other names. In other words: Y.dom has actually become an internal API that does not encourage users to call directly.

But for some reason, I still feel that JQuery's API design is one level higher, and the popular phrase is:
The JQuery API has a better user experience.



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.