Subj : Re: Array Object index question To : netscape.public.mozilla.jseng From : cburdon@tampabay.rr.com (Izman) Date : Wed Oct 29 2003 11:22 am Brendan Eich wrote in message news:<3F9EA9E5.2070407@meer.net>... > > You are constructing a new object every time someone calls obj3(). Why > is that? Wouldn't you rather return the same object each time? > > /be There are a couple of issues I have with returning the same object all of the time. Issue 1 is that I have had problems with the actual coding, probably due to lack of experience and lack of reference material on how to develop C code for use with the js engine. I added a public member variable to JSObject1 for the returned object (JSObject* object3Obj) and used the JS_ConstructObject function to assign it a value in JSObject1's constructor, but then I can't return it's value from a function without the app crashing (and considering you must use JS_GetPrivate to access the data this should probably be expected). Issue 2 is in cases such as the following: var a = Object1.obj3(2); //Line 1 var b = Object1.obj3(4); // 2 var c = a.prop1; // 3 var d = b.prop1; // 4 // 5 var a = Object1.obj3(6); // 6 var e = a.prop1; // 7 If I return the same object all of the time var c would never have the expected value of Object1.obj3(2).prop1, it would return Object1.obj3(4).prop1 wouldn't it? If so, the solution to this issue is easy. I can just make an array of JSObjects that contains an object for each array member, but that leaves me back with Issue 1 that I am having trouble overcoming. So until I can code it a little more efficiently, returning a new object works. Unless of course it would eat up memory because the objects might not get cleaned up (i.e. when line 6 occurs above) or GC would remove the objects while they are still referenced somewhere (like in between lines 2 and 4), 2 of my original concerns. Excluding returning new objects every time the function is called, are there any other issues with the code? Izman .