Fredy Mesia a écrit :
> Hi everyone,
> 
> I get the error : org.mozilla.javascript.EcmaError: TypeError: Cannot find
> function log. (test.js#7) when I execute:
> 
> 
> cx.evaluateReader(scope, *new* FileReader(*new* File("path/test.js")), "
> test.js", 1, *null*);
> 
> My test.js looks like that:
> 
> console.log("s");
> I load Console.class with "ScriptableObject.*defineClass*(scope, Console.*
> class*);" and it looks like this:
> 
> import org.mozilla.javascript.Scriptable;
> import org.mozilla.javascript.ScriptableObject;
> 
> public class Console extends ScriptableObject {
> 
>   static void init(Scriptable scope){}
> 
> 
>   public String getClassName() {
>     return "console";
>   }
> 
>   public static String jsFunction_log(String s){
>     return s;
>   }
> }
> 
> The call to the method "log" works when test.js looks like that:
> 
> var c = new Console();
> c.log
> 
> I would like to make it work in a "static" way without instantiating the
> console object? How can I do this?

I don't like defineClass... (It implies to write more java where I'd 
rather write more js.) Try this:

Java:
package my.pkg;
public class Console {
   public static String log(String s){
     return s;
   }
}

Js:
function log(s) {
        return Packages.my.pkg.Console.log(s);
}

Christophe
_______________________________________________
dev-tech-js-engine-rhino mailing list
dev-tech-js-engine-rhino@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to