4 Replies Latest reply on Sep 14, 2017 7:29 PM by jyoo RSS
    jyoo Newbie

    Javascript 1.7 in Thingworx Server-side script



    I'm trying to use server-side script more effectively, but I got some troubles on that.

    First, As I have known, Thingworx Server-side script uses Rhino 1.7R4 which is based on Javascript 1.7. Then the script should support the functions of Javascript 1.7 such as "let".

    But when I use the "let" statement in the script, it comes out "Sytanx Error". I think Rhino has no problem on that, then is this problem of javascript syntax checker of Thingworx?


    Second, This is similar problem with above. If I use "for ~ in" statement on Array, then It makes the output weird.

    Example codes is below.


    1) Syntax Error of "let"


    2) Error of "for each ~ in". it outputs unknown sentence starts with "_function".


    If anybody knows this kind of problems and reasons, please reply. Thanks.

      • Re: Javascript 1.7 in Thingworx Server-side script
        carlesc Heavyweight Champ

        On TW services there isn't much difference between var and let, as there "isn't" global scope ( it's just the service context which starts and ends on service calls ), then the difference between booth are minimum on a service scope.


        To iterate arrays as far as I know:


        // -- Calls myFunction(item,index) for each array item



        // -- Iterates over each array item and sets item with it's value

        for each(item in myArray) {}


        // -- Iterates over each array item and sets index with the item's index on the array

        for (index in myArray) {}


        // -- Of course the "length" way

        for (var i=0;i<myArray.length;i++) { }


        * On all this samples the only one which can "simulate" let behaviour it's the first one, as all variables in myFunction will be local to myFunction, all the other ( the item, index and i samples ) you will have the variables defined out of for loop scope.