1 var cloneObj = function(obj){ 2 var str, newobj = obj.constructor === Array ? [] : {}; 3 if(typeof obj !== 'object'){ 4 return; 5 } else if(window.JSON){ 6 str = JSON.stringify(obj), //系列化对象 7 newobj = JSON.parse(str); //还原 8 } else { 9 for(var i in obj){ 10 newobj[i] = typeof obj[i] === 'object' ? 11 cloneObj(obj[i]) : obj[i]; 12 } 13 } 14 return newobj; 15 };