Okay, I'm rewriting this because people kept misinterpreting it.
Given two objects x and y, I wish to replace all properties of x with that of y.
(Note that this is not regular cloning as that implies creating a new object (z). Object x is to be updated, not replaced.)
My idea is that one could do this by using two for-in loops (with hasOwnProperty checks), one for removing everything from x and one for copying everything from y to x, but that feels like an ugly solution somehow.
Is there some more elegant way to do this? Does JavaScript (or possibly jQuery) have some built-in function for copying the state of one object into another object that already exists?
 
    