I have JS object with custom methods as prototype (e. g. Foo.prototype.myAwesomeMethod
). If I load my object in a localStorage
and get it later I'll loose these methods.
var foo = new Foo()
console.log(foo.myAwesomeMethod()) // WIN
localStorage.setItem('foo', foo)
foo = localStorage.getItem('foo')
console.log(foo.myAwesomeMethod()) // FAIL...
Is it possible to save the prototype of the object in the localStorage
? If not, how to properly re-instantiate the class?
you can try this
EDIT: my previous code was untested and didn't work, this is the working code