Important: I understand that you want to clone an object ( lastState or an object using the get and set method).
Suppose I have an object A, like this:
var A = { aVariable: "Panem et circencem", aMethod: function () { return (["Veni", "vidi", "vici"]); } };
Now suppose I want to clone an object A to an object B.
function clone(obj) { if (null == obj || "object" != typeof obj) return obj; var copy = obj.constructor(); for (var attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } var B = clone(A);
This is an example:
var A = { aVariable: "Panem et circencem", aMethod: function () { return (["Veni", "vidi", "vici"]); } }; function clone(obj) { if (null == obj || "object" != typeof obj) return obj; var copy = obj.constructor(); for (var attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr]; } return copy; } var B = clone(A); B.aVariable = "Ad gloriam"; console.log(B); console.log (A);
Then you can clone / copy your entire object to have some difference properties in your objects or clone lastState in your code. Sorry, I do not understand this part of your question.
Note: this question will try to answer the question. If I do not understand the question, please give me a comment.
Also note: If I do not answer the question, you can use the above inscription and copy my post to answer the question.
Also note: If you have a question, tell me a comment.
source share