Arnar Birgisson wrote:
> Hi Rush,
> 
> On 2/14/07, Rush Manbert <[EMAIL PROTECTED]> wrote:
> 
>>This is OT, but I AM using MochiKit and you folks are such JavaScript
>>hotshots that I thought I would ask here.
>>
>>For reasons very particular to my application, I have a JavaScript
>>framework that defines 3 object types. Objects of type B contain an
>>array of objects of type A, and object type C contains an array of
>>objects of type B. The objects have function members and the framework
>>maintains a single instance of class C that represents state
>>information. The state info is refreshed via loadJSONDoc.
>>
>>When I first put it all together, I wondered how eval() knew what object
>>type the JSON string represented. It looked like magic. Until I
>>refreshed my object, then tried to call one of its member functions. As
>>you all know, there were no functions. The deserialized objects are just
>>data. So it's not magic, after all, and I was right to doubt that it
>>would do what I wanted.
>>
>>My question is, how do other people deal with this issue? I can write
>>constructors that will build "full" objects from the "data only"
>>objects, sort if like a copy constructor in C++. Is there some better
>>approach?
> 
> 
> If you're willing to break the json std. you can return something like
> "new C([new B([new A('constructor argument'), new A('...'), ...]),
> ...]).
> 
> The string is simply eval'd so if you're constructors are defined you
> should get objects with the correct prototype.
> 

Hi Arnar,

Wow...that's clever. I knew I was asking the right people.

Thanks to you and to Bob for the helpful replies. I'm going to use the 
"copy constructor" approach because I already have a lot of data-only 
json stuff being transferred around. Not to mention that the data source 
is C++ code and I would need to write a custom serializer.

Thanks again,
Rush

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to