x-js-utils
Version:
22 lines (21 loc) • 677 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var test_1 = require("../test");
// 深度克隆
function deepClone(obj) {
// 对常见的“非”值,直接返回原来值
if ([null, undefined, NaN, false].includes(obj))
return obj;
if (typeof obj !== "object" && typeof obj !== 'function') {
//原始类型直接返回
return obj;
}
var o = test_1.default.isArray(obj) ? [] : {};
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];
}
}
return o;
}
exports.default = deepClone;