jQuery.extend () Detailed

jQuery.extend () action method is to use one or more other objects to extend an object.
Typically use the following format:
jQuery.extend (dest, src1, src2, src3 ...);
the above meaning of the code is: the src1, src2, src3 incorporated into dest and returns dest.
Example:

    var dest = {name:'zhu',age:'15'};
    var src1 = {name:'zhang',age:'18'};
    var src2 = {name:'zhou',age:'25'};
    var src3 = {num:15,city:'hongkong'};
    var src4 = {grade:98,course:'math'};
    $.extend(dest,src3,src4);
    console.log(dest);

At this time, the console output dest combined as follows:
image description

Noting jQuery.extend () method will change the object of expanded, if not change the original object, the first parameter set {}.
At the beginning of this article have mentioned jQuery.extend () method is to expand the object is actually an array of objects in JS inside, such as:

var dest = {name:'zhu',age:'15'};
var src = [1,2];
$.extend(dest,src);
console.log(dest);

dest console output is:
image description

In this case the array index value will be merged as attributes.
If the method parameters are two arrays inside it?

var dest = [1,2];
var src = [3,4];
$.extend(dest,src);
console.log(dest);

dest console output is:
image description

If jQuery.extend () method is omitted dest parameter indicates the src incorporated into the global object to jQuery. Examples are as follows:

$.extend({
    test1:function(){alert('hello world');}
        });
$.test1();  //弹出hello world

$.extend({
    test2:'hello world'
        });
alert($.test2);  //弹出hello world

Note that, jQuery.fn.extend (object) is an extension of jQuery element set to provide new methods (commonly used to make plug-in), not to jQuery.extend () method to get confused.

This article is reproduced in: ape 2048➭ https://www.mk2048.com/blog/blog.php?id=hhhkjh2k0bb

Guess you like

Origin www.cnblogs.com/jlfw/p/12540065.html