Created
October 13, 2014 14:54
-
-
Save pingjiang/9a9b39b267a3820c91f6 to your computer and use it in GitHub Desktop.
NodeJS Loop trap, callback is called nextTick.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var files = ['a.txt', 'b.txt', 'c.txt']; | |
for (var i = 0; i < files.length; i++) { | |
fs.readFile(files[i], 'utf-8', function(err, contents) { | |
console.log(files[i] + ': ' + contents); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment