在回调函数中导出变量 ||重新编辑

Export variables within callback functions || Re-edit

本文关键字:新编辑 编辑 变量 函数 回调      更新时间:2023-09-26

真相...我觉得这个问题有点立场

foo(function(err, a){
    foo.buu(function(err, b){
    d = x(b);
    });
});

考虑到结构无法修改。如何访问变量d

考虑到。。。问题真的不知道我的问题就是这个。

var db = new Db(database, server);
db.open(function(err, db){
    list = new Array();
    db.collectionNames(function(err, collections){
        collections.map(function (coll){
            list.push( coll.name ) );
    });
});

但是当进行console.log(list);时,只返回[].我不知道为什么?

变量

d,因为它在代码中,假设它是整个代码,将附加到window

因此,只需d即可访问它。