//forloop.jsvarfs=require('fs');varfiles=['a.txt','b.txt','c.txt'];for(vari=0;ifs.readFile(files[i],'utf-8',function(err,contents){ console.log(files[i]+':'+contents);});}为何输出结果为:undefined:AAAundefined:BBBundefined:CCC改写成forEach//callbackforeach.jsvarfs=require('fs');varfiles=['a.txt','b.txt','c.txt'];files.forEach(function(filename){fs.readFile(filename,'utf-8',function(err,contents){console.log(filename+':'+contents);});});这样结果又对了。。。这是为什么
精慕HU
沧海一幻觉
相关分类