1 //isActiveClone防止循环引用 2 function clone(obj) { 3 if (obj === null || typeof obj !== 'object' || 'isActiveClone' in obj) { 4 return obj; 5 } 6 7 var temp = obj.constructor(); //使temp的prototype与obj的相同 8 9 for (var key in obj) { 10 if (Object.prototype.hasOwnProperty.call(obj, key)) { 11 obj['isActiveClone'] = null; 12 temp[key] = clone(obj[key]); 13 delete obj['isActiveClone']; 14 } 15 } 16 return temp; 17 }