i want to assign one object to an other object to change one object and still have the original object remain unchanged. Since the two objects become just one in the storage with two pointers pointing at it this does not work. How do copie objects with different pointers but the same values.
What is the propper way to do that?
$(document).ready(function(){
var object1 = new theObject("hello");
var object2 = new theObject("hello again");
object1 = object2;
object1.value = "newValue";
// object1.value = "new Value"
// object2.value = "new Value" //should be "hello again"
alert("object1: " + object1.value + " object2: " + object2.value );
});
class theObject{
constructor(value){
this.value = value;
}
}
this works but its not so nice if you have a return value that is an object:
var objKeys = Object.keys(object1);
for (let objKey of objKeys){
object1[objKey] = object2[objKey];
}