[Project_owners] Javascript (de)serialization question

Paul Tomlin paul at paultomlin.com
Sun Mar 12 23:13:16 EST 2006

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

When you eval() the result of toSource(), is the resultant 'instanceof 
foxyproxy.Proxy' true?

If not then I'd check that the class is being included in the toSource() 
output. [NOTE: I've not used the approach myself so I don't know if it 
encodes the class name].

If the class name is there then perhaps ensure the class is defined 
prior to calling eval().

I don't think it's reasonable to expect the language to toSource() 
method definitions in this way. Or more likely the _real_ cause is that 
foo is not a property of 'p', it's a property of the prototype..

So although it's callable when you create it initially (when you define 
the prototype), it's not included in the toSource(). So my 'not 
reasonable' should really say 'not reasonable to expect the language to 
toSource() an entire class hierarchy of methods'.

If initially you do

p = new foxyproxy.Proxy();
p.foo = function () { blah };
alert( p.toSource() );

do you then see 'foo' included in the toSource() output? If so then 
you're back to ensuring the class is defined prior to eval(), and that 
toSource() indeed includes enough info about what class the object 
belongs to.

Persistence of class/meta data is not the same as persistence of 
instance/object data :)

On an entirely different matter, my next commit will be along the lines 
of "finally managed to get prefs, scripts and templated menus working". Yay!

More information about the Project_owners mailing list