//深度克隆
function deepClone(obj) {
var oType = getObjectType(obj);
if (oType == "Object") {
var result = {}
for (key in obj) {
result[key] = deepClone(obj[key]);
}
return result;
} else if (oType == "Array") {
var result = [];
for (var i = 0; i < obj.length; i++) {
result[i] = deepClone(obj[i]);
}
return result;
} else {
return obj;
}
}
function getObjectType(o) {
if (o === null) return "Null";
if (o === undefined) return "Undefined";
return Object.prototype.toString.call(o).slice(8, -1);
}
javascript深度克隆
最新推荐文章于 2024-06-21 13:58:05 发布