js对象如何合并?
var o1={hello:1};
var o2={world:2}
怎样合并得到o3{hello:1,world:2}

var extend=function(o,n,override){   
        for(var p in n)
        if(n.hasOwnProperty(p) && (!o.hasOwnProperty(p) || override))o[p]=n[p];
    };
    var o1={hello:1};
    var o2={world:2};
    extend(o1,o2);
    alert(o1.world);
    alert(o1.hello);

 

 

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2021-08-01
猜你喜欢
  • 2021-11-23
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案