Skip to content
This repository has been archived by the owner on Jun 23, 2019. It is now read-only.

To experiment with native object's shallow cloning in JavaScript #49

Open
motss opened this issue Dec 17, 2017 · 0 comments
Open

To experiment with native object's shallow cloning in JavaScript #49

motss opened this issue Dec 17, 2017 · 0 comments

Comments

@motss
Copy link
Owner

motss commented Dec 17, 2017

Deep clone a JavaScript object by recursively shallow cloning with native JavaScript method:

const a = {
  a: 1,
  b: {
    c: 2,
    d: [1, 2, 3, 4, 5],
    e: () => 'haha',
    f: /\d/i,
    g: new Date(),
    h: { i: 'haha', j: 1, k: [1, 2, 3, 4] },
    l: Promise.resolve(1),
    m: async () => 'lol',
    n: null,
    o: undefined,
    p: NaN,
  },
};
const shallowClone = { ...a };
const deepClone = deepClone(a);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant