美文网首页
$.extend()

$.extend()

作者: 少甜的草莓牛奶 | 来源:发表于2019-07-29 18:01 被阅读0次

    合并多个对象
    $.extend(deep,target,object)
    deep指示是否深度合并对象,默认为false。如果该值为true,且多个对象的某个同名属性也都是对象,则该"属性对象"的属性也将进行合并。,

        var object1 = {
            apple: 0,
            banana: { weight: 52, price: 100 },
            cherry: 97
        };
        var object2 = {
            banana: { price: 200 },
            durian: 100
        }; 
        // 将 object2 递归合并到 object1中
        $.extend( true, object1, object2 );
        结果:
        object1: {"apple":0,"banana":{"weight":52,"price":200},"cherry":97,"durian":100}
        
        $.extend( false, object1, object2 );
        结果:
        {"apple":0,"banana":{price:200},"cherry":97,,"durian":100}
    
    

    相关文章

      网友评论

          本文标题:$.extend()

          本文链接:https://www.haomeiwen.com/subject/xfrirctx.html