[Project_owners] Javascript (de)serialization question

Eric H. Jung grimholtz at yahoo.com
Sun Mar 12 18:02:08 EST 2006


Hi Nickolay,

> > I'm trying to use toSource() and eval() for serialization and deserialization of JS objects of
> my
> > own class. I find that serialization works, but the object's type ("class") is lost on
> > deserialization. For example, given the following class:
> 
> IMO you should keep serializable data in a separate object (not a class, a 
> simple object), but if you really want to, you can set the "class" of an object, 
> after it is deserialized, by setting __proto__ manually (to Proxy.prototype).
> 


So __proto__ points to the prototype object? How is Proxy.__proto__ different from
Proxy.prototype?


> You didn't explain the problem you're trying to solve though, - *why* do you 
> want to serialize your classes?


I want to serialize _data_ to a file so the user doesn't have to re-enter settings across brower
invocations. The data evolved from simple Arrays of Arrays to classes for just one reason: to make
construction of the objects easier. Now I learned yesterday that:

foxyproxy.Proxies = function() {}
foxyproxy.Proxies.prototype = new Array(); // this overwrites the ctor above, so now reassing
it...
foxyproxy.Proxies.prototype.constructor = foxyproxy.Proxies; 

permits me to define a custom constructor for Array "subclasses". So I'm not sure if that can help
me get rid of the classes, but it sounds like you're suggesting if I want to use
toSource()/eval(), I should try to stick with just Arrays and Objects, right?




More information about the Project_owners mailing list