Subj : Re: Serializing JavaScript in spidermonkey To : Marcello Bastea-Forte From : Brendan Eich Date : Thu Jan 01 2004 04:44 pm Marcello Bastea-Forte wrote: > >> Yes, see my post at >> news://news.mozilla.org:119/3FF27935.6090803@meer.net, specifically: > > > Ok, it seems I never sent an email I had written up in response to that. > > I wrote some code to test toSource and uneval: > > var state = new Array(); Why are you using an Array here? You want Object, not Array, and you can say all this more concisely with an object literal (aka object initializer): var state = {beat_boss: true, name: "j0", number: 3}; Use an Array if you want length to be automatically maintained based on the greatest index used to access a property, and if you are indexing (using non-negative integer property ids). Use Object otherwise. /be > state['beat_boss'] = true; > state['name'] = "j0"; > state['number'] = 3; > state['array'] = new Array(); > state['array']['beat_boss'] = true; > state['array']['name'] = "j0"; > state['array']['number'] = 3; > > print(uneval(state)); > print(state.toSource()); > > > The output I get is: > [] > [] > > Marcello .