function cloneObj(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; };
本文共 318 字,大约阅读时间需要 1 分钟。
function cloneObj(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/AmbitiousMice/p/6813635.html