Extend functions in jQuery _ jquery-js tutorial

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.