The extension method in jquery extend using tips _jquery

Source: Internet
Author: User

In the process of using jquery, Extend is a commonly used parameter processing function, especially for default values.

The extension method prototype for jquery is:

var v=$.extend (DEST,SRC1,SRC2,[,SRC3 ...]);

The effect is to merge the SRC1,SRC2,SRC3 into the Dest and return the merged dest.

But in the process of using, the default value is often cannot be changed,

As follows:

var defaut={' selector ': ' SELECT ', ' Default ': ' Defaults ', ' BackColor ': ' #85e137 ', ' ForeColor ': ' #000 '};

var src={' selector ': ' ss ', ' Default ': ' Jokes ', ' BackColor ': ' #fff ', ' ForeColor ': ' Red '};

If we use

var v=$.extend (DFAULT,SRC);

To handle the parameters, the default value for the next processing is the value after this process rather than the actual 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), the default parameter as the first source parameter (SRC), which also returns the merged parameters, but our default is not changed and can be used again!

This enables the default value to remain the same effect!

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.