title: Function within function in JavaScript - Need to understand this code:
body: <p>I have below code within a function called render. How do I call the str variable value outside render function? </p>
  
  <p>Also, please can you explain below code? I'm fairly new to js and head is hurting looking at the function calls having functions as a parameter.</p>
  
  <p>My understanding is that app.getList is an object which takes function as a parameter? but it is not returning anything. Sorry, I'm lost here.</p>
  
  <pre><code>app.getList("FieldList", function(reply){
      var str = "";
      $.each(reply.qFieldList.qItems, function(index, value) {
          str +=  value.qName + ' ';
      });
      console.log(str);
  });
  </code></pre>
  
  <p>Full Code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>define(["jquery",
      //mashup and extension interface
      "qlik",
      //add stylesheet
      "text!./css/mystyle.css",
      "client.utils/state",
      "client.utils/routing"
    ],
    function($, qlik, cssContent, clientState, clientRedirect) {
  
  
      /*-----------------------------------------------------------------*/
      // function redirect (sheetId){
      // clientRedirect.goToSheet(sheetId, Object.keys(clientState.States)[clientState.state])
      // }
      /*-----------------------------------------------------------------*/
  
  
      /*-----------------------------------------------------------------*/
      var render = function($elem, layout) {
  
  
        var html = '',
          app = qlik.currApp();
  
  
        //get list of tab objects and insert into div
        app.getAppObjectList('sheet', function(arrayitem) {
  
  
          //for each sheet in the app, create a list item
          $.each(arrayitem.qAppObjectList.qItems, function(myindex, myvalue) {
  
  
            //include the sheet id as the list item id to be used as a reference for active sheet
            html += '&lt;li id="' + myvalue.qInfo.qId + '"&gt;'; // onClick="redirect(' + value.qInfo.qId + ');
  
  
            //wrap anchor tag to be used by bootstrap styling
            html += '&lt;a&gt;';
  
  
            //give the link the same name as the sheet
            html += myvalue.qData.title;
  
            html += '&lt;/a&gt;';
            html += '&lt;/li&gt;';
          });
  
  
          html += '&lt;/ul&gt;&lt;/div&gt;';
  
  
          html += "&lt;button id='myButton'&gt; Click Me!! &lt;/button&gt;";
  
  
          console.log(arrayitem.qAppObjectList);
          console.log(html);
  
  
          //insert html into the extension object
          return $elem.html(html);
        });
  
        /* Test Code Start from here */
  
        app.getList("FieldList", function(reply) {
          var str = "";
          $.each(reply.qFieldList.qItems, function(key, value) {
            str += value.qName + ' ';
          });
          console.log(str);
        });
  
      };
      /*-----------------------------------------------------------------*/
  
  
      return {
        /*-----------------------------------------------------------------*/
        paint: function($element, layout) {
  
          console.count();
  
          /*-----------------------------------------------------------------*/
          $(function() {
            $element.html("#myButton").click(function() {
              // for(var mynum = 1; mynum &lt;= 5; mynum++){
              //   alert('button test' + mynum);
              // };
            });
          });
          /*-----------------------------------------------------------------*/
  
  
          render($element, layout);
          /*-----------------------------------------------------------------*/
        }
      };
  
  
    });</code></pre>
  </div>
  </div>
  </p>