How to Use extended method extend in Jquery: jqueryextend

Source: Internet
Author: User

How to Use extended method extend in Jquery: jqueryextend

During Jquery development, extend is a common parameter processing function, especially for the use of default values.

The Extension Method prototype of Jquery is:

var v=$.extend(dest,src1,src2,[,src3...]);

The function is to merge src1, src2, and src3 into the dest and return the merged dest.

However, the default value cannot be changed during use,

As follows:

Var defaut = {'selector ': 'select', 'default': 'default', 'backcolor':' # 85e0000', 'forecolor': '#000 '}; var src = {'selector ': 'ss', 'default': 'joke', 'backcolor': '# fff', 'forecolor': 'red '};

If we use

var v=$.extend(dfault,src);

For parameter processing, the default value for the next processing is the value after the processing, 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) and use the default parameter as the first source parameter (src). In this way, the merged parameter is returned, however, our default has not been changed and can be used again!

In this way, the default value remains unchanged!


You can use extend ({example and explain it to JQUERY ).

The extend extension method is prototype extend (dest, src1, src2, src3 ...);
It means to merge src1, src2, src3... into the dest, and the returned value is the merged dest. It can be seen that the structure of the dest is modified after the method is merged. If you want to obtain the merged result but do not want to modify the dest structure.

Var newSrc = $. extend ({}, src1, src2, src3 ...)

In this way, you can merge src1, src2, src3... and return the merged result to newSrc.

That is to say, if the following parameter has the same name as the preceding parameter, the following parameter will overwrite the preceding parameter value.

Var result = $. extend ({}, {name: "Tom", age: 21 },{ name: "Jerry", sex: "Boy "})

Then the merged result
Result = {name: "Jerry", age: 21, sex: "Boy "}

The dest parameter in the extend method prototype can be omitted. If this parameter is omitted, the method can only have one src parameter and merge the src parameter into the object that calls the extend method.

$. Extend ({hello: function () {alert ('hello') ;}}); merge the hello method into the global object of jquery.

How can I use the selector to select the class name $ ("className") for the jqueryfnextend extension method?

Try $ (". className"). eq (0). comeOn ();

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.