Currently in my Javascript code, I am utilizing localStorage. Since objects cannot be directly stored in it, I am using JSON.stringify to serialize them before saving.
Within localStorage, I am storing the entire game state, where some of the sub-objects contain methods.
However, when retrieving these objects with JSON.parse, the methods are no longer present - which is expected behavior. Storing objects with methods in the browser would not be ideal.
What is the most effective way to reattach these methods to the object so that it functions as it did originally?
Would setting up something like
savedObj.prototype = MyClass.prototype;
be a suitable solution or am I overlooking something?