ってゆーか、Proxyを使わなくても

こんな感じで


public class MethodMissing extends ScriptableObject {

private Function handler = null;

public MethodMissing(Function handler) {
this.handler = handler;
}

public Object get(final String name, Scriptable o) {
return new BaseFunction() {
public Object call(Context cx, Scriptable scope, Scriptable f, Object args) {
Object
new_args = new Object[1 + args.length];
new_args[0] = name;
System.arraycopy(args, 0, new_args, 1, args.length);
return handler.call(cx, scope, null, new_args);
}
};
}

public String getClassName() {
return this.getClass().getName();
}

}

こう呼び出して


var o = new MethodMissing(function() {
print("name:" + arguments[0]);

for(var i=1; i

こうなる…と。


name:foo
name:bar
a
name:zoo
B
12