如何从嵌套的匿名函数javascript返回值

时间:2015-03-31 09:52:04

标签: javascript function anonymous-function nested-function

如何从波纹管内部匿名函数返回值。

function getDayFromCalendar() {
    var db = openDatabase('Calendar', '1.0', 'myapp', 2 * 1024 * 1024);
    db.transaction(function (tx) {
        tx.executeSql('SELECT * FROM calendar LIMIT 1', [], function (tx, results) {
            return results.rows.item(0).date;
        });
    });
}

1 个答案:

答案 0 :(得分:0)

function getDayFromCalendar() {
    var db = openDatabase('Calendar', '1.0', 'myapp', 2 * 1024 * 1024);
    var outerResult = db.transaction(function (tx) {
        var innerResult = tx.executeSql('SELECT * FROM calendar LIMIT 1', [], function (tx, results) {
            return results.rows.item(0).date;
        });
        // here you have inner function result
        return innerResult;
    });
    // here you have outer function result
    alert(outerResult);
}