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