Tag: 词汇范围

Nodejs asyn.apply和Javascript应用

有人可以请解释我为什么下面的代码打印“arg1 0”,而我期望它打印“arg1嗨”。 这是由于词汇范围? runIt(); function localScoped(arg1, callback) { console.log('arg1', arg1); callback(); } function runIt() { var myValue = 0; async.eachLimit(["hi"], 1, function launchOneVar(clientCode, doneLaunchOneVar) { async.waterfall([ function (myCallback) { myValue = clientCode; myCallback(); }, async.apply(localScoped, myValue) ], function (err, result) { console.log(myValue); doneLaunchOneVar(null, result); }); }, function finishing(err) { } ); }