This article mainly introduces the details of extend functions in jQuery. For more information, see
1. $. extend ({}, defaults, options)
The purpose is to protect the default parameters of the package. That is, the parameters in ults.
The method is to use a new Null Object ({}) as $. the first parameter of extend, defaults and the parameter object passed by the user follow closely. The advantage of doing so is that all values are merged into this empty object, protecting the default values in the plug-in.
$. Fn. myPlugin = function (options) {var defaults = {'color': 'red', 'fontsize': '12px '}; var settings = $. extend ({}, defaults, options); // use an empty object as the first parameter return this.css ({'color': settings. color, 'fontsize': settings. fontSize });}
2. code obfuscation and Compression
In the plug-in you download, a compressed version is generally provided with a 'Min' in the file name. That is, the description of minified.
Compression here is not a function compression of the Code. Instead, it replaces the variable names and method function names in the Code with shorter names and deletes comments (if any) delete the blank space between codes and the concentrated version obtained by line feed. At the same time, because the various names in the Code have been replaced, other people can not read and clear their logic, it also plays a role in obfuscation of code.
Benefits of compression: 1. Less code, faster loading, and improved performance
2. Prevent code theft by others
The above is all the content of this article. I hope you will like it.