On Mar 4, 9:33 am, howa <[EMAIL PROTECTED]> wrote:
> On 3月4日, 下午10時07分, Norris Boyd <[EMAIL PROTECTED]> wrote:
>
> > On Mar 4, 8:44 am, howa <[EMAIL PROTECTED]> wrote:
>
> > > On 3月4日, 下午6時48分, Attila Szegedi <[EMAIL PROTECTED]> wrote:
>
> > > > Define o as:
>
> > > > o = { a: 7, b: function() { return this.a+1; }}
>
> > > > Attila.
>
> > > > On 2008.03.04., at 7:40, howa wrote:
>
> > > > > Sample codes:
>
> > > > > /*************************************/
> > > > > ScriptEngineManager mgr = new ScriptEngineManager();
> > > > > ScriptEngine engine = mgr.getEngineByName("js");
> > > > > try {
> > > > > engine.eval("o = { a:7, get b() { return this.a+1; }}; k =
> > > > > o.b;");
> > > > > System.out.println(engine.get("k"));
>
> > > > > } catch (Exception e) {
> > > > > e.printStackTrace();
> > > > > }
> > > > > /*************************************/
>
> > > > > Error returns:
>
> > > > > javax.script.ScriptException:
> > > > > sun.org.mozilla.javascript.internal.EvaluatorException: missing :
> > > > > after property id (<Unknown source>#1) in <Unknown source> at line
> > > > > number 1
> > > > > at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
> > > > > at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
> > > > > at javax.script.AbstractScriptEngine.eval(Unknown Source)
>
> > > > > Any idea?
>
> > > > > Howard.
>
> > > Yes, but I want to know why Getter didn't work when embedded in my
> > > Java codes.
>
> > > P.S.
>
> > > it is okay if I use the js.jar shell,
>
> > > e.g.
>
> > > java -jar js.jar
>
> > > >> load("getter.js");
>
> > > This is works as expected.
>
> > The version of Rhino used in javax.script is older and does not
> > support getters and setters.
>
> > --N
>
> Yes, but why the js.jar shell came with the rhino work? (I assume they
> are using the same engine?)
>
> A little bit strange...
>
> Howard
Which version of js.jar are you using? I assume it is 1.6R6 or later
as that's when getters were implemented (see
http://developer.mozilla.org/en/docs/New_in_Rhino_1.6R6#JavaScript_1.5:_Getters_and_Setters).
The version in javax.script is earlier.
--N
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino