I need to create deepclones of veryBigObject. veryBigObject needs to be init first via initVeryBigObject. This is how it looks like:
initVeryBigObject = function(){
veryBigObject = {};
...
//Very Long Calculations to calculate the value of stuff.
...
veryBigObject = {data:stuff}
}
initVeryBigObject();
var clone = JSON.parse(JSON.stringify(veryBigObject)); //slow
or
eval('createClone = function(){ return ' + JSON.stringify(veryBigObject) + '}');
var clone = createClone(); //turns out to be x3 faster
I'm not a big fan of eval but it's the only fast way I see to clone an object that requires init. Am I missing something?
EDIT: This question isn't really a duplicate of "Most efficient way to clone an object?". The methods talked in "Most efficient way to clone an object?" are about cloning different objects using the same function.
My question is about cloning one particular object multiple times and obviously, methods discussed in "Most efficient way to clone an object?" are far slower than what I'm suggesting with my eval "strategy".