Utilizing JSON.stringify
and JSON.parse
to save and retrieve objects from localStorage
has led to a discovery - JSON.stringify
seems to remove the instance functions from the object. This means that once I use JSON.parse
, I lose the ability to execute myObject.doSomething()
. While I can manually attach this function like so:
myObject.doSomething = MyClass.prototype.myFunction
, this could become tedious if repeated often in the web app. How do developers typically handle this scenario in JavaScript?