In the process of using Jquery to develop, extend is a commonly used parameter processing function, especially the use of default values.
Jquery’s extension method prototype is:
var v=$.extend(dest,src1,src2,[,src3...]);
The function is to merge src1, src2, src3 into dest and return the merged dest.
But during use, the default value often cannot be changed,
is as follows:
var defaut={'selector':'select','default':'默认值','backcolor':'#85e137','forecolor':'#000'}; var src={'selector':'ss','default':'笑话','backcolor':'#fff','forecolor':'red'};
If we use
var v=$.extend(dfault,src);
to process the parameters, then the default value the next time it is processed will be the value after this processing instead of the real default value.
We can use the following code:
var v=$.extend({},dfault,src);
That is, we use an empty object as the target parameter (default) and the default parameter as the first source parameter (src). In this way, the merged parameters are also returned, but our default has not been changed, which is OK Use it again!
This achieves the effect of keeping the default value unchanged!