Detailed parsing of Extend functions

Source: Internet
Author: User

1. Feel the water is deep

functionJQuery () {}jquery.extend= JQuery.prototype.extend =function() {    varsrc, copyisarray, copy, name, options, clone,//If there is no parameter target = {}, some words target is the first parameter;Target= arguments[0] | | {},    //index i is 1;i = 1; Length=Arguments.length, deep=false; //If the first argument is a Boolean value, assign it to deep, and then continue traversing arguments    if(typeoftarget = = ' Boolean ') { deep=Target; Target= arguments[I] | | {}; ++i; }    //    if(typeofTarger!== ' object ' &&!jquery.isfunction (target)) {Target= {}; }    //when only one parameter assigns this value to jquery or Jquery.fn to target, it depends on how the user invokes it; there are two branches; if this parameter is   //Boolean, it is not possible to enter the loop at this time, and the target will return directly, if this parameter is not    if(i = =length) {Target= This; --i; }     for(; i < length; i++ ){        if(options = Arguments[i])! =NULL ){             for(Nameinchoptions) {src=target[name]; Copy=options[name]; if(target = =copy) {                    Continue; }                if(Deep && copy && jquery.isplainobject (copy) | | (Copyisarray =jquery.isarray (copy))) ){                    if(Copyisarray) {Copyisarray=false; Clone= src && jquery.isarray (src)?src: []; }Else{Clone= src && jquery.isplainobject (src)?src: {}; } target[Name]=jquery.extend (deep, clone, copy); } Else if(Copy! =undefined) {target[name]=copy; }            }        }    }    returnTarget;}; Jquery.isfunction=function(obj) {returnObject.prototype.toString.call (obj). Slice (8,-1). toLowerCase () = = ' function ';} Jquery.extend ({},{"1":true, "2": "false"});

Detailed parsing of Extend functions

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.