I have a Javascript class in ES6, and I want to write a LoadFromJson method.
the problem is that JSON.parse return an object and I cannot write :
//MyObject.loadFromJson method
loadFromJson(JsonString)
{
this=JSON.parse(jsonString); //INVALID//
}
How can I achieve this from within my class. I know I could write :
myObject = JSON.parse(jsonString);
but that's not what I want, I need :
myObject = new MyObjectClass();
myObject.loadFromJson(JsonString);
I want to implement an "undo mechanism" in my object and to be able to save / restore the object.