title: Java Nashorn create JS object in Java, when I have an object representing JS function
body: <p>I have a base class, that takes <code>Entity</code> as its constructor argument. I extend this base class in JavaScript, and it looks like this:</p>
  
  <pre><code>Java.extend(BaseClass, {
         someAbstractMethod : function() { ... },
         someAdditionalField : ...,
         etc
  })
  </code></pre>
  
  <p>As far as I understood, I cannot use the additional fields / methods if I have instance of it as a Java object, but I can if it is a JavaScript object. So how do I instantiate this class as JS object with Java code?</p>
  
  <pre><code>public class ScriptedEntity extends Entity implements Scripted&lt;EntityScriptFunctions&gt; {
  
      private CompiledScript script;
      private Object implemented_script_class;
      private Object my_script_instance;
      private Invocable invocable;
  
      public ScriptedEntity(float x, float y, CompiledScript script) {
          super(x, y);
          invocable = (Invocable) script.getEngine();
          try {
              implemented_script_class = script.eval();
              my_script_instance = invocable.invokeFunction("???", this); //'this' is the constructor argument
          } catch (ScriptException | IllegalArgumentException | NoSuchMethodException | SecurityException e) {
              e.printStackTrace();
          }
      }
  
      ...
  
  }
  </code></pre>