const isObject = function(obj) { if (obj === null || obj === undefined) return false; if (typeof obj === "object") return true; }; const isArray = function(arr) { return Array.isArray(arr); }; const deepClone = function(obj) { if (!isObject(obj)) return obj; let cloneObj = isArray(obj) ? [] : {}; for (let key in obj) { if (obj.hasOwnProperty(key)) { let value = obj[key]; if (isObject(value)) { cloneObj[key] = deepClone(value); } else { cloneObj[key] = value; } } } return cloneObj; };
分别对extend 和 clone 库进行了性能测试比对... 发现extend 贼牛逼
源码分析 : extend