$.extend (obj1,0bj2,{"name": "S", "Age":)//target on which object to copy//I want to copy the length of the parameter to be copied//The name object parameter in the property value//Options pair Copy of object attributes with duplicate of image parameter//clone deep copy//target object to expand Jquery.extend = JQuery.fn.extend = function () {var src, copyisarray, copy, n Ame, options, clone, target = Arguments[0] | | {},//Common usage jquery.extend (obj1, Obj2), at which point the target is arguments[0] i = 1, length = Arguments.length, D Eep = false; Handle a deep copy situation if (typeof target = = = "Boolean") {//If the first parameter is true, that is, Jquery.extend (true, OBJ1, OB J2); The case of deep = target; At this point target is true target = arguments[1] | | {}; Target change to obj1//Skip the Boolean and the target i = 2; }//above processing: If the first parameter is a Boolean, the second parameter is target. Handle case when Target was a string or something (possible in deep copy) if (typeof target!== "Object" && !jquery.isfunction (target)) {//If Target is not an object, set the default object. target = {}; }//Extend JQuery itselfIf only one argument is passed if (length = = = i) {//handle this case jquery.extend (obj), or jQuery.fn.extend (obj) ta Rget = this; Jquery.extend when this refers to Jquery;jquery.fn.extend, this refers to Jquery.fn-I.; } for (; i < length; i++) {//-deal with non-null/undefined values if (options = Arguments[i] ) = null) {//For example Jquery.extend (, Obj2, Obj3, OJB4), options are Obj2, obj3 ...//Extend the Base object for (name in options) {src = target[name]; copy = options[name]; Prevent never-ending loop if (target = = = copy) {//Prevent self-referencing: $.extend (x,{"name1": x}); if Target and Opti ON[NAME1] is the same as the value of the loop iteration. See online also said should be used with SRC and copy comparison, $.extend ({"name1": "Zhang San", "Age": "Name1"},{"John Doe": "The", "Age": "14"}), these two can be manipulated. Continue }//Recurse If we ' re merging plain objects or arrays//if it is a deep copy, and the copied property value itself is an object if (deep && copy && jquery.isplainobject (copy) | | (Copyisarray = Jquery.isarray (copy))) {if (Copyisarray) {//copied attribute value is array copyisarray = false; clone = src && jquery.isarray (src)? SRC: []; } else {//copied property value is a plainobject, such as {nick: ' casper '} clone = src && jquery.isplainobject (SRC)? src: {}; }//Never move original objects, clone them target[name] = Jquery.extend (deep, C Lone, copy); Recursive ~//Don ' t bring in undefined values} else if (copy!== undefined) {//Shallow copy, and property value is not u ndefined target[name] = copy; }}}}//Return the modified object return target; {name1: "SDASD", "name2": {name1: "SDASD", "name2": {name1: "SDASD", "name2": {name1: "SDASD", "name2": {name1: "SDASD", " Name2 ": {NAME1: "SDASD", "name2": {name1: "SDASD", "name2": {name1: "SDASD", "Name2":}}}}}}
jquery Extend Source parsing