Subj : Re: Assigning an l-value expression programmatically To : netscape.public.mozilla.jseng From : Brendan Eich Date : Tue Oct 21 2003 01:42 pm Harizakis Costas wrote: > Hi, > > I would like to ask if there is a way to perform programmatically the >following ... > >foo.bar.i = "value"; > > ... given that I have access to the left and right parts of the >assignment - say the strings "foo.bar.i" and "value". > > Let me re-phrase my question in a more general form: Suppose that I have 2 >JavaScript expressions. The 1st holds the left part of the assignment >(l-value expression) and the 2nd holds the right part of the assignment >(r-value). Using the JS_ExecuteScript(...) I can evaluate a jsval for the >r-value. How can I gain access to the object/property pair (l-value) which >is the receiver of the evaluated r-value? > > My actual problem arises when I have the l-value in a string form, the >r-value already evaluated (as a jsval) and I want to assign the latter on >the former. > > I'm curious why you have the left-hand side in a string -- is that something a user types in? Do you have to check that it's well-formed? Could it be arbitrariliy complex (a[i+4][j/2].b.c[k*3].d, e.g.)? If you have the right-hand side as a string, the easiest course, which wins also if you need syntax checking, is to concatenate the LHS, " = (", the RHS, and ")" and then JS_EvaluateString. There is no API to evaluate an lvalue. It seems better to understand the problem you're solving before saying more. /be .