【转】数组、对象的深拷贝

链接:https://www.zhihu.com/question/23031215/answer/31944721

var cloneObj = function(obj){
	var str, newobj = obj.constructor === Array ? [] : {};
	if(typeof obj !== 'object'){
		return;
	} else if(window.JSON){
    	str = JSON.stringify(obj), //系列化对象
    	newobj = JSON.parse(str); //还原
	} else {
    	for(var i in obj){
		    newobj[i] = typeof obj[i] === 'object' ? 
		    cloneObj(obj[i]) : obj[i]; 
	    }
    }
    return newobj;
};
原文地址:https://www.cnblogs.com/xfh0192/p/7661706.html