Eric H. Jung wrote:
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?

Heh, and there you were complaining about the "heavy stream of Javascript newbies" at mozillazine :)

|prototype| is a property of a constructor function ("Proxy"). When a new object is created using that function ("new Proxy"), one of the things that happens, is that the Proxy.prototype object is added to the __proto__ chain of the object instance. In other words:

  var obj = new Proxy();

does this assignment, among other things:

  obj.__proto__ = 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.
If you want to serialize data, serialize data. I'm not sure I understand what you mean with: >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:


I find this set up to be strange, not sure what you're trying to accomplish with it. If you're just trying to have certain Array generics available on your instances, add them directly to the prototype.
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?

I suggested not using custom 'classes', yes.

Nickolay

_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners

Reply via email to