js对象如何合并?

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);

 

 

posted @ 2013-03-31 01:39  microsoftzhcn  阅读(357)  评论(0编辑  收藏  举报