我在另一个函数中有这个回调函数 -
var getData = function(){
var x ="";
myCollection.find().toArray(function(err,records){ //myCollection is declared somewhere else
x = "this is where I set my variable";
});
console.log(x); //x is just blank
}
如何在回调函数中设置变量x,以便它仍然在函数范围之外保留该值?是否可以?