Extend function in jquery _jquery

Source: Internet
Author: User

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

This is done to protect the package default parameters. That is, the parameters inside the defaults.

The idea is to make a new empty object ({}) the first parameter of the $.extend, followed by the defaults and the user-passed Parameter object, which has the advantage that all values are merged onto the empty object, protecting the default values within the plug-in.

$.fn.myplugin = function (options) {
  var defaults = {
    ' color ': ' Red ',
    ' fontsize ': ' 12px '
  };
  var settings = $.extend ({},defaults, options);//An empty object as the first argument return
  this.css ({
    ' color ': Settings.color,
    ' fontsize ': Settings.fontsize
  });


2. Code obfuscation and compression

You download the plugin inside, generally will provide a compressed version of the general name in the file with a ' min ' words. Which means minified, compressing the condensed version.

The compression here does not mean that the code does function compression, but instead replaces it with a shorter name by changing the name of the variable in the code, the method function name, and so on, and deletes the annotation (if any) to remove the blank between the code and the condensed version of the line. At the same time, because the various names in the code have been replaced, others can not read and distinguish their logic, also played a role in confusing the code.

Benefits of compression: 1. Less code, faster loading speed, better performance

2. Prevent others from stealing code

The above mentioned is the entire content of this article, I hope you can enjoy.

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.