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

Detailed example of simple usage of extend function in jQuery

小云云
Release: 2017-12-26 17:13:16
Original
1471 people have browsed it

This article mainly introduces the simple usage of the extend function in jQuery, and briefly analyzes the related operation skills of jQuery using the extend function to extend object properties in the form of examples. Friends who need it can refer to it. I hope it can help everyone.

The example in this article describes the simple usage of the extend function in jQuery. Share it with everyone for your reference, the details are as follows:

var result=$.extend({},item,item1);
Copy after login

extend Add new attributes to the object: js plug-ins are often used to configure parameters
{}: The result of merging item and item1
item: Default attributes
item1: New attributes. If item1 and item attributes overlap, the attributes in item1 will be overwritten.

<span id="Test"></span>
Copy after login
var item={"name":"olive","age":23};
var item1={"name":"Momo",sex:"gril"};
var result=$.extend({},item,item1);
console.log(JSON.stringify(result));
$("#Test").text(JSON.stringify(result))
Copy after login

Result:

Analysis:

The results show that the name attribute of item1 covers the name attribute of item, and the non-overlapping attributes of item and item1 objects will not affect each other and will be inherited by the result object. Many js frameworks set the default Configuration, and then through the extend function, users can customize relevant configurations to achieve personalized use of the framework.

Related recommendations:

JQuery’s extend method analysis

Detailed examples of using the object.extend static method in Javascript

jquery extend and fn.extend

The above is the detailed content of Detailed example of simple usage of extend function in jQuery. For more information, please follow other related articles on the PHP Chinese website!

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!