title: How to store function handles from ScriptManager for later usage?
body: <p><strong>tl;dr:</strong><br />
  How do/can I store the function-handles of multiple js-functions in java for using them later? Currently I have two ideas:</p>
  <ol>
  <li><p>Create multipe ScriptEngine instances, each containing one loaded function. Store them in a map by column, multiple entries per column in a list. Looks like a big overhead depending on how 'heavy' a ScriptEngine instance is...</p>
  </li>
  <li><p>Some Javascript solution to append methods of the same target field to an array. Dont know yet how to access that from the java-side, but also dont like it. Would like to keep the script files as stupid as possible.</p>
  <pre><code> var test1 = test1 || [];
   test1.push(function(input) { return &quot;&quot;; });
  </code></pre>
  </li>
  <li><p>???</p>
  </li>
  </ol>
  <p>Ideas or suggestions?</p>
  <hr />
  <p><strong>Tell me more:</strong><br />
  I have a project where I have a directory containing script files (javascript, expecting more than hundred files, will grow in future). Those script files are named like: <code>test1;toupper.js</code>, <code>test1;trim.js</code> and <code>test2;capitalize.js</code>. The name before the semicolon is the column/field that the script will be process and the part after the semicolon is a human readable description what the file does (simplified example). So in this example there are two scripts that will be assigned to the &quot;test1&quot; column and one script to the &quot;test2&quot; column. The js-function template basically looks like:</p>
  <pre><code>    function process(input) { return &quot;&quot;; };
  </code></pre>
  <p>My idea is, to load (and evaluate/compile) all script files at server-startup and then use the loaded functions by column when they are needed. So far, so good.</p>
  <p>I can load/evaluate a single function with the following code. Example uses GraalVM, but should be reproducable with other languages too.</p>
  <pre><code>    final ScriptEngine engine = new ScriptEngineManager().getEngineByName(&quot;graal.js&quot;);
      final Invocable invocable = (Invocable) engine;
      
      engine.eval(&quot;function process(arg) { return arg.toUpperCase(); };&quot;);
      var rr0 = invocable.invokeFunction(&quot;process&quot;, &quot;abc123xyz&quot;); // rr0 = ABC123XYZ
  </code></pre>
  <p>But when I load/evaluate the next function with the same name, the previous one will be overwritten - logically, since its the same function name.</p>
  <pre><code>    engine.eval(&quot;function process(arg) { return arg + 'test'; };&quot;);
      var rr1 = invocable.invokeFunction(&quot;process&quot;, &quot;abc123xyz&quot;); // rr1 = abc123xyztest
  </code></pre>