您将需要使用javascript进行异步调用和回调,这不是c#/ php等。
这是使用您的代码的示例:
function get_info(data, callback){ var sql = "SELECt a from b where info = data"; connection.query(sql, function(err, results){ if (err){ throw err; } console.log(results[0].objid); // good stuff_i_want = results[0].objid; // Scope is larger than function return callback(results[0].objid); }}//usagevar stuff_i_want = ''; get_info(parm, function(result){ stuff_i_want = result; //rest of your pre goes in here });当您
get_info依次调用此
function(err, results)函数时,将调用connection.query,它接受一个回调(这就是
作用域,然后将范围传递给此回调,依此类推。
欢迎使用Javascript回调地狱…
当您掌握它时很容易,只是需要一点点习惯,就来自C#之类的东西



