Underscore source reading record

Source: Internet
Author: User

These days have great God recommended to read underscore source code, take advantage of the project test blank time, looked at a bit.

The whole underscore includes the common tool functions, the following 1.3.3 source code for example analysis.

function (obj) {        return _.isarray (obj)? obj.length: _.keys (obj). length;    };

The whole underscore source code is basically the above way to write, so understand the above source code, the entire underscore source is probably clear six or seven, the remaining source code with some time, it will be solved.

Because there is _.keys in the above function, it may not be clear at once, the following function source code easier to get started.

  

  function (obj) {        return obj!== obj;    };

Just figure out what the object _ and the function parameter obj are doing.

var function (obj) {         returnnew  wrapper (obj);     };

_ is defined as a function that takes a formal parameter named obj, and then returns an instance of the wrapper class.

Underscore source reading record

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.