Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Strict-mode into Javascript

    Hi Isomorphic,

    Some of the Global variables are easily leaked in Javascript. Inorder to avoid this, we thought of adding Strict-mode into the javascript created by our SGWT framework.
    Is there any way to do so ?
    please guide me.


    Thanks,
    Manjula

    #2
    What do you mean by "Global variables are easily leaked in Javascript" and what problem do you think is created here?

    Comment


      #3
      Hi Isomorphic,

      We would like to add "use strict" in the start of our Javascript files which will be created by our SGWT framework. Do we have any option to enable it ?

      Thanks,
      Manjula

      Comment


        #4
        Hi Manjula,

        As we asked before: is there some problem you are trying to solve? If so, if you can tell us the actual problem, we can help you solve it.

        Comment


          #5
          If it is not clear, we are asking:

          1. what effect would having "use strict" have on your development process, especially since you are using Java, not JavaScript?

          2. which are the files where you hope to apply it - there are files generated by GWT, core SmartClient framework files, skin files, etc

          Just as a guess: you may have just hired a junior JavaScript developer, or perhaps installed a new tool, and either way, some party is asserting that "use strict" must always be applied? This is not true - "use strict" has benefits and drawbacks. But junior engineers and/or poorly designed tools may erroneously flag it as an issue.

          Comment


            #6
            Hi Isomorphic,

            Please find the below issue we want to address.

            Global variables are easily leaked in Javascript. You may consider the following javascript code used in the default, non-strict mode:

            function f()

            Unknown macro: { Token = 1; }

            f();
            console.log("I can still see Token: " + Token);

            The default, non-strict mode allows some relatively "unsafe" actions to be taken, and it allows some code mistakes that make it difficult for JavaScript engines to perform optimizations.

            Recommendations:

            To prevent these mistakes from happening, add 'use strict'; at the beginning of your JavaScript files. This enables a stricter mode of parsing JavaScript that prevents accidental globals. Strict mode makes several changes to normal JavaScript semantics. First, It prevents, or throws errors, when relatively "unsafe" actions are taken. Second, strict mode eliminates some JavaScript silent errors by changing them to throw errors.

            Is there any option to enable strict mode to the javascript being created by our SGWT framework?

            Thanks,
            Manjula

            Comment


              #7
              Hi Manjula, SmartGWT (actually the underlying SmartClient engine) already avoids needlessly creating global variables, and all necessary global variables have prefixes.

              So there is nothing to be gained here - no "mistakes" or "unsafe actions" are being taken, and we would recommend that, in the future, you ignore random recommendations like this, as they often come from naive / inexperienced sources.

              Comment

              Working...
              X