When I try to overwrite the get function of a class, amazing thing
happens.

public class Counter extends ScriptableObject{
public Counter(){
 System.out.println(this);
}
...........
private String id;

public void setId(String id){
   this.id = id;
}

public void jsSet_id(String id){
    this.id = id;
}
public String jsGet_id(){
    return this.id;
}
public Object get(String name, Scriptable start){
   System.out.println("Counter get "+name);
   Object obj = super.get(name, start);
   if(obj!=Scriptable.NOT_FOUND)
     return super.get(name, start);
   System.out.println("this "+this);
   System.out.println("start "+start);
}

.............
}

The test code like this:
            Object[] arg = { new Integer(7) };
            Scriptable myCounter = cx.newObject(scope, "Counter",arg);
            scope.put("c", scope, myCounter);
            Counter counter = (Counter)myCounter;
            counter.jsSet_id("id1");
The js code is very simple ,just like this:
         c.id;
After running it, I get the following results:

   "  [EMAIL PROTECTED]
      [EMAIL PROTECTED]
     Counter get id
     this [EMAIL PROTECTED]
     start [EMAIL PROTECTED]

     Counter get id "!


Now I want to know why the "
   Counter get id " appears twice?   I think It only appear once!

When I write the js code as this
   c.id1
The result is like this

   "  [EMAIL PROTECTED]
      [EMAIL PROTECTED]

     Counter get id1
     this [EMAIL PROTECTED]
     start [EMAIL PROTECTED]

     Counter get id1
     this [EMAIL PROTECTED]
     start [EMAIL PROTECTED]
      "
  Why there exist two objects, [EMAIL PROTECTED] object just keep
the class level attribute?  Can you explain this simply for me?
  Thank you!


_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to