So "obj instanceof A" becomes "obj instanceof B".
As of persistence case I've solved it on JavaScript internal implementation level. In Sciter there is built-in JSON-ish data persistence module - close to Mongo-DB on feature set (modulo sharding).
Storage loads objects as half-backed proxies that contain only db references. Only when code tries to access props/methods of the loaded object it gets fetched from disk, its __proto__ is set to particular class, etc.
More on this architecture: https://gitlab.com/sciter-engine/sciter-js-sdk/-/blob/main/d...
By the way, dynamic subclassing is not a prerogative of only dynamic languages, here is how I did that in C++: https://stackoverflow.com/questions/21212379/changing-vtbl-o...
Patched QuickJS with storage support is here: https://gitlab.com/c-smile/quickjspp - it uses DyBase of Konstantin Knizhnik as a storage.