Thursday, January 23, 2014

make a copy of one JavaScript object to another without the two objects referencing each other

You may not want to update a property at one object and have it update a property at another. Perhaps you want to grab a snapshot of something managing state in the moment for logging. Here is how you do that per StackOverflow:

app.exposeViewOpeners = function() {
   var openers = getOpeners();
   var snapshot = JSON.parse(JSON.stringify(openers));
   console.log(snapshot);
};

No comments:

Post a Comment