pvorb / clone

deeply clone arbitrary objects in javascript

Home Page:https://www.npmjs.com/package/clone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't clone npm modules

narayanmp opened this issue · comments

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.

You could just do

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