Require javascript-object-paraphernalia
var obj = require('javascript-object-paraphernalia')Define an objects for use with the following examples
var exampleFirst = {
fruit: "Apple",
animals: {
firstAnimal: "Beaver"
}
};Use obj.clone to clone the first example object
var exampleClone = obj.clone(exampleFirst)exampleClone's contents:-
{
fruit: "Apple",
animals: {
firstAnimal: "Beaver"
}
}Update the clone's inner properties
exampleClone.fruit = "Orange"
exampleClone.animals.cloneOnlyAnimal = "Rabbit"Compare the clone with the first example object
exampleFirst = {
fruit: "Apple",
animals: {
firstAnimal: "Beaver"
}
}
exampleClone = {
fruit: "Orange",
animals: {
cloneOnlyAnimal: "Rabbit",
firstAnimal: "Beaver"
}
}