Returning values from nested functions in Javascript
<p>Consider this code (shortened)  </p>

<pre><code>function getSecret() {
    db.transaction(
        function (transaction) {
            transaction.executeSql(
                'SELECT * FROM table LIMIT 1;',
                null,
                function(transaction, result) {
                    var row = result.rows.item(0);
                    var secret = row.secret;
                    return secret;
                }, errorHandler
            );
        }
    )
}
</code></pre>

<p>How would I return the value of secret to the main function? I have read this answer <a href="http://stackoverflow.com/questions/2611980/return-value-from-nested-function-in-javascript">Return value from nested function in Javascript</a></p>

<p>And tried this</p>

<pre><code>function getSecret() {
    db.transaction(
        function doSql(transaction) {
            transaction.executeSql(
                'SELECT * FROM table LIMIT 1;',
                null,
                function(transaction, result) {
                    var row = result.rows.item(0);
                    var secret = row.secret;
                    return secret;
                }, errorHandler
            );
        }
    )
    return doSql;
}
</code></pre>

<p>However this did not work.</p>

<p>Thanks!</p>
