javascript error: In strict mode code, functions can only be declared at top level or immediately within another function

0

When testing my application on an android 4.4, this error appears, however on android 5 the error does not appear.

Someone knows how to tell me what it can be.

    
asked by anonymous 07.04.2018 / 22:55

1 answer

0

Following Vitor's suggestion in the comment my question, I was able to identify and solve the problem, I decided to write this answer to help someone who may have the same problem.

The Problem

In some algorithms I created a function within a condition or loop, that is until it generates error, in that the error does not occur. From Android 5, the webview starts to implement es6, so the error no longer occurs.

Example:

function getNome(){
   if (nome !== null){

      return nome();

      function nome(){
         return _nome;
      } 
   }
}

Solution

In order for the problem to not occur, we must remove the declaration from function name () from within if .

function getNome(){
   if (nome !== null){
      return nome();
   }

   function nome(){
      return _nome;
   }
}

So it works perfectly.

    
14.04.2018 / 21:47