I want to use rhino (JavaScript) function.apply() to pass arguments to the Java varags method, something like this:
function sprintf() { return java.lang.String.format.apply(arguments); } sprintf("%d\n", 5);
But calling sprintf() gives an error:
Error: can't find method java.lang.String.format().
I suppose this is because the format() method is not a proper JavaScript function, but a Java method, so it does not have apply() . (Although this is not what the error message seems to be, maybe not.)
I found that I can add my own apply () method:
java.lang.String.format.apply = function() {}
But I don’t see how to write apply() without apply() , if you understand what I mean. Any ideas?
source share