Advertisement
magrega

egor's denial

Jan 3rd, 2023
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.76 KB | Source Code | 0 0
  1. const _ = require('lodash');
  2.  
  3. const obj = [{
  4.     x: 1
  5. }, {
  6.     y: 2,
  7.     z: {
  8.         1: "string"
  9.     },
  10.     sym: Symbol('foo'),
  11.     func: function() {
  12.         console.log("Hey!");
  13.     }
  14. }];
  15.  
  16. const deepCopy = _.cloneDeep(obj);
  17.  
  18. deepCopy.funcTwo = function() {
  19.     console.log("BYE!");
  20. };
  21. deepCopy.symTwo = Symbol("foo");
  22.  
  23. console.log('Comparing original with deep ',
  24.     obj[0] === deepCopy[0]);
  25.  
  26. // Changing original value
  27. obj[0].x = 10;
  28.  
  29. console.log("After changing original value");
  30.  
  31. console.log("Original value ", obj);
  32.  
  33. console.log("Deep Copy value ", deepCopy);
  34.  
  35. console.log(obj.sym === deepCopy.sym);
  36. console.log(obj.sym === deepCopy.symTwo);
  37. console.log(obj.func === deepCopy.func);
  38. console.log(deepCopy.funcTwo === deepCopy.func);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement