Monday 5 June 2017

have access to a variable after callback is called

There is an existing API that I'd rather not change that gets the connection to a database. The signature looks like

getDBConnection(function(error, DBConnection) {
   // do biz logic
});

There is another variable that I want to use within getDBConnection

var foo; // actually has some value i want
getDBConnection(function(error, DBConnection) {
     // foo = undefined
});

But foo is undefined in the getDBConnection callback. Is there somethign I can do to have access to Foo within getDBConnection?



via Crystal

No comments:

Post a Comment