我的编码风格显然是同步的。如果我有以下代码:
#!/usr/bin/env node
/*
* AUTHOR :
* CREATED :
* VERSION :
* PURPOSE :
*/
'use strict';
var $COLUMNS = 3;
var $people = [];
function main() {
readFile('data.csv');
printFile();
writeFile();
}
function readFile($filePath) {
var $IN = require('ya-csv');
var $reader = $IN.createCsvFileReader($filePath, {
separator: ','
});
$reader.on('data', function($item) {
$people.push($item);
}).on('end', function() {
console.dir($people);
});
}
function printFile() {
for (var $i = 0; $i < $people.length; $i++) {
for (var $j = 0; $j < $COLUMNS; $j++) {
process.stdout.write($people[$i][$j] + ' ');
}
process.stdout.write('\n');
}
}
function writeFile() {
var $OUT = require('ya-csv');
var $writer = $OUT.createCsvFileWriter('dataX.csv', {
quote: ''
});
$people.forEach(function($item) {
$writer.writeRecord($item);
});
}
main();
是否可以全局使用$ people中的值,并像我一样使用main()调度?