Thanks for the reminder of a child's shoes! Say my last essay. jquery plug-in development of the way one can also be used for merging parameters and deep clone, although the way to do a method of a combination of parameters, but not described in detail, so today do a bit of a supplement here!
first, merging parameters
The Extend extension prototype for jquery is:
Extend (arg,arg1,arg2,......);
return value not arg1,arg2 ... Merge to Arg. There are two ways to use it.
var results=$.extend ({name: ' Nick '},{sex: ' Handsome '});//Then the return value is results={name: ' Nick ', Sex: ' Handsome '}, custom arg parameter, The arg of the custom type is returned. For example://defines ARG as an object var results=$.extend ({},{name: ' Nick '},{sex: ' Handsome '});//Then, the return value is arg object results={name: ' Nick ', sex: The ' handsome '};//here defines arg as an array var results=$.extend ([],{name: ' Nick '},{sex: ' Handsome '});//Then, the return value is the arg array results=[name: ' Nick ', Sex: ' Handsome '];
Attention:
When merging parameters, if the attribute name of the parameter in $.extend () conflicts, the following value replaces the previous value. Such as:
This defines arg as an object var results=$.extend ({},{name: ' Nick ', Sex: ' Male '},{sex: ' Handsome '});//Then, the return value is the Arg object. Sex attribute conflicts, the following value handsome replace Maleresults={name: ' Nick ', Sex: ' Handsome '};
Second, clone
The Extend clone of jquery is:
$.extend (Boolean,arg,arg1,arg2 ...);
var results=$.extend (true,{},{user:{name: ' Nick ', Love: ' Money '},age:25},{user:{name: ' Summer ', like: ' Car '},sex: ' Handsome '});//return value results={"user": {"name": "Summer", "Love": "Money", "like": "Car"}, "age": "Sex": "Handsome"};
var results=$.extend (false,{},{user:{name: ' Nick ', Love: ' Money '},age:25},{user:{name: ' Summer ', like: ' Car '},sex: ' Handsome '});//return value results={"user": {"name": "Summer", "like": "Car"}, "age": "Sex": "Handsome"};
Have you noticed, dear? Take a good look at the return value!
Attention:
- It is best to set the Boolean to True when $.extend () is used for clone.
- Since earlier versions of jquery had only shallow clones, but later versions were fixed, use the jquery CDN as much as possible with the higher version.
Supplemental $.extend ()