[Original] two interesting points in jquery's first line of code

Source: Internet
Author: User

SeeJqueryThe first and last linesCode

(Function(Window, undefined) {}) (window );

This anonymous structure is not uncommon. What we are talking about today is not this,Second Parameter,JqueryHe has not passed the value. Why?We know that parameters without passing values will be setWindow. undefinedWhy?JqueryNot used by developersWindow. undefinedInstead of using a form parameter?

Think about it. There are at least two points worth doing this (please add ):

    1. undefined is set as a local variable. Local variables can be used directly in the current scope. You do not need to search for the upper-level scope chain to reduce the number of searches and improve the efficiency.
    2. check the compressed code. (function (a, B) {}) (window) , undefined is cleverly replaced with B , in the subsequent Code, many judgments use undefined . B . Local variables are replaced by short characters during compression, which effectively reduces the size of the compressed file, therefore, many local variables are pulled out and set, not only for temporary storage results, but also for compression.

Code there are a lot of exquisite ideas that are worth learning. They all use language skills, thoughts are important.

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.