In my game, I save the current state by converting all the objects to JSON and then saving that to a file. Some objects, like enemies, have functions on them, but JSON can\'
I think that you have to save the type on your object so that the functions can be re-added at parsing time. E.g. put a type
property on your enemy in the constructor. At parsing time, first parse the string like normal JSON and then deep-traverse the resulting object. When you encounter something that was an Enemy
, re-attach the methods or so.