自定义 cloneObj 方法
//深复制对象var cloneObj = function (obj) { var newObj = {}; if (obj instanceof Array) { newObj = []; } for (var key in obj) { var val = obj[key]; newObj[key] = typeof val === 'object' ? cloneObj(val) : val; } return newObj;};
本文共 327 字,大约阅读时间需要 1 分钟。
自定义 cloneObj 方法
//深复制对象var cloneObj = function (obj) { var newObj = {}; if (obj instanceof Array) { newObj = []; } for (var key in obj) { var val = obj[key]; newObj[key] = typeof val === 'object' ? cloneObj(val) : val; } return newObj;};
转载于:https://www.cnblogs.com/senyier/p/7337943.html