我在我的项目中为js(es6)添加了linters,对于新配置,我发现它们阻止使用const内部函数 – 仅用于模块级常量.内部函数我应该使用let.但我无法找到这种规则的任何理由.为什么?
对于jscs来说就是这样
disallowConstOutsideModuleScope:
const
should only be used in module scope (not inside functions/blocks)
我知道我可以配置和关闭该规则,我只是想知道它启用了什么?这种检查的动机是什么?
附:我有链接https://madhatted.com/2016/1/25/let-it-be与块“常量常量”
There is another school of thought on when to use let and const I’ll need to address. This strategy suggests developers use const as much as possible. Any variable that is not re-assigned should be declared with const.
I think this usage is poor practice. It adds an extra distraction to the process of programming,and results in code difficult to understand and change.
但我发现这些论点很有价值
解决方法
这只是一个编码指南.他们遵循
this学院的思想.如果您不想使用它,请随时在.jscsrc文件中将其关闭.要点是:
- Aggressive use of const devalues the operator
- Choosing const first really means choosing to think about every declaration. Will the next line of code change this assignment? How
will I use this variable?- There is no known performance difference between let and const.