What is the best way to clone an object in node.js
e.g. I want to avoid the situation where:
var obj1 = {x: 5, y:5};
var obj2 = obj1;
obj2.x = 6;
con
There is another library lodash, it has clone and cloneDeep.
clone will clone your object but not create a new instance for non-primitive values, instead it will use the referrence to the original object
cloneDeep will create literally new objects without having any referrence to the original object, so it more safe when you have to change the object afterwards.