• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Arrow function in global script

    Scripting general Discussion
    3
    5
    1.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Desmond
      last edited by Desmond

      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

      1 Reply Last reply Reply Quote 0
      • CraigWebC
        CraigWeb
        last edited by

        I believe that mango implements Rhino JS. Which is not fully compatible with ES6 yet.

        1 Reply Last reply Reply Quote 0
        • D
          Desmond
          last edited by Desmond

          @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

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by phildunlap

            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
            
            1 Reply Last reply Reply Quote 0
            • CraigWebC
              CraigWeb
              last edited by

              Hence the removal of RhinoJS from the help documents. My bad I probably should of looked first.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post