代码如下: var fs = require(‘fs’);
var readFile = function (fileName) { return new Promise(function (resolve, reject) { fs.readFile(fileName, function(error, data) { if (error) reject(error); resolve(data); }); }); }; var asyncReadFile = async function (){ var f1 = await readFile(’./test.txt’);
console.log(f1.toString());
};
我的node版本是 v7.1.0 执行命令的时候开了–harmony 报错: var asyncReadFile = async function (){ ^^^^^^^^ SyntaxError: Unexpected token function at Object.exports.runInThisContext (vm.js:78:16) at Module._compile (module.js:545:28) at Object.Module._extensions…js (module.js:582:10) at Module.load (module.js:490:32) at tryModuleLoad (module.js:449:12) at Function.Module._load (module.js:441:3) at Module.runMain (module.js:607:10) at run (bootstrap_node.js:420:7) at startup (bootstrap_node.js:139:9) at bootstrap_node.js:535:3
搞不懂为什么。 请有经验的大哥们帮我解决这个问题了,感激不尽。