Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't clone npm modules #112

Open
narayanmp opened this issue Jun 12, 2020 · 1 comment
Open

Doesn't clone npm modules #112

narayanmp opened this issue Jun 12, 2020 · 1 comment

Comments

@narayanmp
Copy link

I am trying to clone an npm object like below.

const obj1 = clone( require('an-npm-module'));
const obj2 = clone( require('an-npm-module'));

But after doing operations on both, the changes are reflected in both objects. I am doing this because the same npm is used by parent and other npm modules and I want their own copies to avoid other issues.

Based on the documentation it looks like clone supports deep copy by default. Any help in achieving it is appreciated.

@johannbuscail
Copy link

johannbuscail commented Jul 14, 2020

You could just do

const obj1 = {...require('an-npm-module')}
const obj2 = {...require('an-npm-module')}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants