copying the data copy

Copy (OBJ1, obj2) {
var obj2 obj2 || = {}; // first time to give it an initial value = itself or a JSON
for (var name in OBJ1) {
IF (typeof OBJ1 [name] == = "object" && obj1 [name ]! == null) {// first determine what obj [name] is not an object (null are objects will complain)
obj2 [name] = (obj1 [name] == .constructor = array) []:? { }; // we let the name of the object to be copied item = array or json
this.copy (obj1 [name], obj2 [name]); // call the function yourself then infinite recursion Thought
} the else {
obj2 [name] = OBJ1 [name]; // if the object is not directly equal to, a reference does not occur.
}
}
Return obj2; // copy and then return to a good object out
},
// Call
obj1 = copy1 (obj, obj2) ;

Guess you like

Origin www.cnblogs.com/wssdx/p/12157897.html