function deepCopyObj (source) { let newObj = JSON.parse(JSON.stringify(source)); copyFunction(newObj, source); return newObj; //深拷贝function; function copyFunction(newObj, source) { for(let i in source) { let tmpProp = source[i]; if(typeof tmpProp == 'function') { newObj[i] = source[i]; } else if(typeof tmpProp == 'object') { copyFunction(newObj[i], source[i]); } } } }
js深拷贝对象
最新推荐文章于 2024-09-15 20:31:42 发布