JQ's Extend () method can conveniently implement the extended object method, the syntax is as follows: $.extend (OBJ1,BOJ2,OBJ3);
Now to achieve is: the original JS implementation of replication objects, extended objects, similar to the JQ in the Extend () method, specific examples are as follows:
Existing 3 objects literal:
var o1={hello:1,old:555},
O2 = {
abc:55555555,
hello:2,
fun:function () {
alert ()}
} ,
o3={third:9999};
To achieve the goal:
Copy the O1 object, extend the O2,o3 object properties and methods into the previously copied object and output.
<script> var o1={hello:1,old:555}, O2 = {abc:55555555, hello:2, Fun:function () {
Alert (111);
}, o3={third:9999}; function Cloneobj (oldobj) {//Copy object method if (typeof (Oldobj)!= ' object ') return oldobj; if (oldobj = null) return oldobj; var
NEWOBJ = new Object ();
for (var i in oldobj) newobj[i] = Cloneobj (Oldobj[i]);
return NEWOBJ;
}; function Extendobj () {//Extended object var args = arguments; if (Args.length < 2) return; var temp = Cloneobj (args[0));//Call Replication Object
Method for (var n = 1; n < args.length n++) {for (var i-args[n]) {temp[i] = args[n][i];} return temp;
} var t=extendobj (O1,O2,O3);
Console.log (t);
Console.log (O1);
Console.log (O2);
Console.log (O3); </script>