Home > Web Front-end > JS Tutorial > body text

Detailed explanation of extend function in jQuery_jquery

WBOY
Release: 2016-05-16 15:50:34
Original
1282 people have browsed it

1.$.extend({},defaults, options)

The purpose of this is to protect the package default parameters. That is, the parameters in defaults.

The method is to use a new empty object ({}) as the first parameter of $.extend, followed by defaults and the parameter object passed by the user. The advantage of this is that all values ​​​​are merged into this empty object. On the object, the default value in the plug-in is protected.

$.fn.myPlugin = function(options) {
  var defaults = {
    'color': 'red',
    'fontSize': '12px'
  };
  var settings = $.extend({},defaults, options);//将一个空对象做为第一个参数
  return this.css({
    'color': settings.color,
    'fontSize': settings.fontSize
  });
}

Copy after login

2. Code obfuscation and compression

The plug-in you download will usually provide a compressed version with the word 'min' in the file name. That is to say, minified, a compressed and condensed version

The compression here does not refer to the functional compression of the code, but by replacing the variable names, method function names, etc. in the code with shorter names, and deleting comments (if any) and deleting code spaces. A condensed version of the whitespace and line breaks. At the same time, since various names in the code have been replaced, others cannot read and distinguish its logic, which also plays a role in confusing the code.

Benefits of compression: 1. Reduce the amount of code, speed up loading, and improve performance

2. Prevent others from stealing the code

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!