在ES6中,是否可以在严格模式下使用const
在try{}
中设置变量?
'use strict';
const path = require('path');
try {
const configPath = path.resolve(process.cwd(), config);
} catch(error) {
//.....
}
console.log(configPath);
由于configPath
的定义超出了范围,因此无法实现lint.唯一可行的方法是:
'use strict';
const path = require('path');
let configPath;
try {
configPath = path.resolve(process.cwd(), config);
} catch(error) {
//.....
}
console.log(configPath);
基本上,在这种情况下,有没有办法用const
而不是let
?