Yui 3 Study Notes: Dom

Source: Internet
Author: User

The hierarchical structure of the Yui Dom module is clear:

Expanded detail: yui-dom-full.png

Some experiences
  1. The submodules organization mode is very clear. The division of labor between submodules is clear, and the source code is as clear as haoyue.
  2. Selector-css3 uses the plugin method, reserved in the selector-css2 Extended Interface, css3 directly expand pseudo class and operator. This extensible writing method is also used multiple times in detailed code, such as writing some compatible code for IE. The code is independent and can be added and cut, very cute.
  3. Flexibility of small particles is also costly. Some code may be duplicated between submodules. The value is not worth mentioning.
  4. The ternary operator is a good thing:
    getText: (document.documentElement.textContent !== undefined) ?
    function(element) {
    var ret = '';
    if (element) {
    ret = element.textContent;
    }
    return ret || '';
    } : function(element) {
    var ret = '';
    if (element) {
    ret = element.innerText;
    }
    return ret || '';
    }

    In different browsers, gettext points to different functions, and the judgment in the ternary operator only needs to be executed once.
    There is also a way to write:

    _childrenByTag: function() {
    if (document[DOCUMENT_ELEMENT].children) {
    return function(element, tag, fn, toArray) {
    ...
    };
    } else {
    return function(element, tag, fn) {
    ...
    };
    }
    }()

    The function that returns the function is quite useful.

  5. Before reading the source code, I will try to answer a question: how can I design the DOM API and draw a picture? Finally, the API and
    In contrast to yui3, in my design, the functions are comprehensive, but in terms of hierarchical classification and definition, yui3 is much better. In general, comparing and learning API design has a fascinating world.
  6. I did not go into the code details this time. I keep reminding myself to look at the overall situation. If you are willing to give it up, you can get it.

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.