Let's say I have obj1
with only enumerable properties:
var obj1 = { a: 1, b: 2, c: 3 };
I then create obj2
which holds a reference to obj1
:
var obj2 = obj1;
obj1 === obj2; // true
At some point, I want to reset obj1
to an empty object:
for (key in obj1) {
delete obj1[key];
}
obj1 === obj2; // true
But I'd like to avoid having to iterater over all the properties:
obj1 = {};
obj1 === obj2; // false (this obviously doesn't work)
Is there another solution?