1 function copy(obj){ //浅拷贝 2 var result = {}; 3 for(var attr in obj){ 4 result[attr] = obj[attr]; 5 } 6 return result; 7 } 8 9 function copy(obj){ //深拷贝 10 var result = {}; 11 for(var attr in obj){ 12 if(typeof obj[attr] == 'object'){ 13 result[attr] = copy(obj[attr]); 14 } 15 else{ 16 result[attr] = obj[attr]; 17 } 18 } 19 return result; 20 }