Subj : Re: [spidermonkey]How to: get another variable values from JS? To : netscape.public.mozilla.jseng From : Brendan Eich Date : Thu Jun 30 2005 11:16 am Brendan Eich wrote: > laser wrote: > >> I also have another question, when I use spidermonkey to excute JS >> like: >> >> var ln = 5; >> var ln1; >> ln1 = ln*2; >> >> I can get the values of variable ln1 by using API JS_EvaluateScript and >> JSVAL_TO_INT, but how can I get the values of variable ln? > > > > The value of a script is the value of the last expression statement > evaluated in it. That may be what you mean by "get the value of ln1" > (the *rval out parameter of JS_EvaluateScript, for this script). To get > ln, you could call JS_GetProperty(cx, global "ln", &v). Oops, dropped a , after global in that call expression -- of course, global denotes the object you passed to JS_EvaluateScript as the |obj| second parameter (*). /be (* Or the last object on obj's scope chain, linked by the parent slot, if different from obj. See JSOPTION_VAROBJFIX comments in jsapi.h.) .