Hello Nashorn folks,

I have a JavaScript object, and I'd like to 'override' what the index operator [] does on it.

I.e. when I do

var x = myobj[3];

I actually want it to call some other function on the object, e.g.

myobj.get(3);

I'm pretty sure this isn't possible in pure JS, so I was thinking of wrapping a Java Object as a JavaScript object, e.g. if I have

public class MyJavaClass {
   public Object get(int index) {
      ...
      return something;
   }
}

I would like to have a JS wrapper for it, such that when I call:

var x = myJavaWrapper[3];

It actually calls:

myJavaObject.get(3);

Is this possible in Nashorn?

Reply via email to