[Project_owners] Javascript (de)serialization question

Eric H. Jung grimholtz at yahoo.com
Sun Mar 12 14:03:34 EST 2006


Warning: This was posted at http://forums.mozillazine.org/viewtopic.php?t=388554, but I'm hoping
to get a more timely reply from this group. IMHO, the quality of forums.mozillazine.org has
suffered in recent months, I think due to a heavy stream of Javascript newbies. Nickolay, I
apologize if this dual-post offends you. I am only trying to make progress - to move forward in a
reasonable time.

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:

foxyproxy.Proxy = function(name, notes, enabled, selectedTabIndex, matches, manualconf, autoconf)
{
  this.name = name ? name : "";
  this.notes = notes ? notes : "";
  this.enabled = enabled;
  this.selectedTabIndex = selectedTabIndex ? selectedTabIndex : 0;
  this.matches = matches ? matches : new Array();
  this.manualconf = manualconf ? manualconf : new foxyproxy.Proxy.ManualConf();
  this.autoconf = autoconf ? autoconf : new foxyproxy.Proxy.AutoConf();   
}
foxyproxy.Proxy.prototype.foo = function() {alert("foo");}

When I write this:

var p = eval(new foxyproxy.Proxy().toSource());

I cannot call p.foo(). This makes sense because toSource() doesn't appear to output functions
defined on an object. Is there anyway to make this work? How do you use toSource()/eval() on your
own classes?

Thanks in advance for any help,
Eric Jung


Use Your PC To Find a Cure for Cancerhttp://members.ud.com/services/teams/team.htm?id=68C9E079-8285-495F-8598-D73352CC7075And Join Team Lulu


More information about the Project_owners mailing list