1.深克隆

  1. /*
  2. * 深度合并对象
  3. */
  4. function deepAssign(FirstOBJ, SecondOBJ) {
  5. if (!typeof FirstOBJ == 'object' && typeof SecondOBJ == 'object') return;
  6. for (var key in SecondOBJ) {
  7. FirstOBJ[key] = FirstOBJ[key] && FirstOBJ[key].toString() === '[object Object]' ? deepAssign(FirstOBJ[key], SecondOBJ[key]) : (FirstOBJ[key] = SecondOBJ[key]);
  8. }
  9. return FirstOBJ;
  10. }