Arrow function in global script
-
Hi All,
I am trying to do some code in Mango global script using arrow function in javascript.
var func = (x, y) => { return x + y; }; print(func(1,2));
Result:
<eval>:4:30 Expected : but found x var func = (x, y) => { return x + y; }; ^ in <eval> at line number 4 at column number 30<br/>at line: , column:
However it does not evalute the expression. I am unsure the Mango scripting environment does support the ES6. Any feedback will be appreciated.
Thanks & Best Regards
-
I believe that mango implements Rhino JS. Which is not fully compatible with ES6 yet.
-
@CraigWeb,
Thank for your prompt reply.It will then be a wishlist to stack in Mango/Mozilla road map to implement ES6 for Rhino JS in the near future as functional programming languages have become more popular.
By the way, anyone know the current version of Rhino JS used in Mango?
Thanks & Regards
-
Hi Desmond,
Craig has led you astray. The JavaScript engine is bundled into the Java distribution, and if you are using Java 8 (which is currently the version we recommend) you are on the Nashorn JavaScript engine. If you are using Java 7, you are probably also using an old version of Mango, but you should be able to use Java 8 on that old version. RhinoJS was the JavaScript engine in 7.. Stack overflow would have me believe JDK8 may only have a subset of ES6 available to it: https://stackoverflow.com/questions/46898540/unable-to-execute-es6-on-java-8-with-nashornscriptengine including no arrow functions.
You can probably run Mango on Java 9 as things are right now,but there may be lingering compatibility issues as we haven't focused on moving to Java 9, 10, 11 (so many to choose from...). But I believe we've at least fixed the bugs that prevent you from using 9 or 10 (there may be some issues on the github for the ma-core-public project concerning known incompatibilities, like I believe there is some issue starting on SSL in Java 10, etc.)
To the question of ES6, Nashorn DOES support ES6 (or at least some), but not by default. One need either instantiate the JavaScript engine with the ES6 flag (we've discussed making arguments possible to send to the script engine factory, since there are other cool options too!), or set it more globally with an ext-enabled script, then stopping, then starting (not restarting) Mango like,
#!/bin/bash case "$1" in init) # Start with Nashorn toggled to support some ES6 features JAVAOPTS="$JAVAOPTS -Dnashorn.args=--language=es6" ;; esac
-
Hence the removal of RhinoJS from the help documents. My bad I probably should of looked first.