util.js 373 B

1234567891011121314151617
  1. /* 深拷贝 */
  2. export const deepClone = (obj) => {
  3. const newObj = {};
  4. let keys = Object.keys(obj);
  5. let key = null;
  6. let data = null;
  7. for(let i = 0; i<keys.length;i++){
  8. key = keys[i];
  9. data = obj[key];
  10. if(data && typeof data === 'object'){
  11. newObj[key] = deepClone(data)
  12. }else{
  13. newObj[key] = data;
  14. }
  15. }
  16. return newObj
  17. }