Normen a écrit :
>> Do you try to expose an indexed property? (A property which, according to
>> java beans conventions would be: getFlags(int i)... and that in javascript
>> you'd like to expose as flags[i]?)
>
> exactly this is what iam trying to do!
Ok, your trouble comes from the fact that "x = this.flags[2]" is
equivalent to :
var flags = this.flags;
x = flags[2]; // no more reference to "this"
So your jsGet_flags() need to return something thas is array-like and
that remembers where it comes from.
Given your code sample, one way to do this is to use an
org.mozilla.javascript.Delegator.
private String[] flags;
public Object jsGet_flags()
{
Scriptable scope = ScriptableObject.getTopLevelScope(this);
Context cx = Context.getCurrentContext();
Scriptable array = cx.newObject(scope, "Array", this.flags.length);
return new Delegator(array) {
public Object get(int index, Scriptable start) {
// TODO: if index is out of bounds, call super.get... or
return Scriptable.NOT_FOUND;
return ParentClassName.this.flags[index];
}
// you also need to override has(int, Scriptable) and put(int,
Scriptable, Object);
// ...
};
}
Hope this helps.
Christophe
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino