On 13 feb, 17:42, Christophe Grand <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] a écrit :
>
> > However, I tried the solution in Rhino shell and when calling eval it
> > prints the code, but does not evaluate it. Is there any other way so
> > to print the code and evaluate it?
>
> Strange: here what I get:
> js> eval("2+2")
> 2+2
> 4
>
> It is both printed and evaluated. Can you do the exact same test and/or
> provide an excerpt of your shell session?
Ok, I understand why it was not working. The example I tried was :
js> eval("2+2")
2+2
4
js> eval("var t=1+1+1+1")
var t=1+1+1+1
js> t
js: "<stdin>", line 11: uncaught JavaScript runtime exception:
ReferenceError: "t" is not defined.
I got the argument printed, but the variable t was not defined when
trying to access it afterwards. But I remembered that eval changes the
scope (am I right??), then it is logical that the variable t does not
exist in the current scope.
If I define the variable t in the Shell, and then use eval and set t
to value 1+1+1+1 then it works, what I get is:
js> var t
js> t=1
1
js> t
1
js> eval("t=1+1+1+1+1")
t=1+1+1+1+1
5
js>t
5
js>
Thanks a lot for your help;)
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino