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

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

@motss

Description

@motss

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions