I was using ClearScript
with .NET
to expose Classes to Javascript. I used this to expose class (not instance of class to JS) : engine.AddHostType("Worker", typeof(Worker));
So I could use var x = new Worker();
In javascript
;
Now in Nashorn
with Java this does not work. I am only able to expose instance of class like this : factory.getBindings().put("Worker", new Worker());
Is there a way to expose class type to javascript with Nashorn.
Thank you!
Your script can directly access any Java class by fully qualified name such as
If you don't want the script to directly refer to your Java class or perhaps you want to provide a different name, you could do something like this:
Hope this helps!