这个问题类似于:为什么我们在缩小的 JavaScript 中有换行符?
在这种情况下,我更喜欢半打左右的换行符。为什么缩小器将代码和样式减少到一行?即使在生产代码上,我也可能有我没有考虑到的错误。虽然其他人可能是专业的 100% 完美的开发人员,但我希望可以选择至少插入十几个换行符。我已经避免缩小代码了。到现在为止,我想要更多的性能,但也想要一些代码审查的平衡。
也许不是每个函数都换行,但至少每个类对象都需要换行,因为我使用了很多自定义的 React 组件类。
漂亮的:
var num = 10;
const dothis = function() {
let x = 0;
for(x = 0; x < num; x++) {
...
};
function dothat(){
var foo = 'Hello';
let name = 'World';
var bar = foo + name;
console.log(bar);
}
Uglified
var num=10;const dothis=function(){let x=0;for(x=0;x<num;x++){...}};function dothat(){var foo = 'Hello';let name = 'World';var bar = foo + name;console.log(bar);}
Something in between
var num = 10;
const dothis = function() { let x=0; for(x = 0; x < num; x++) {...};
function dothat(){ var foo = 'Hello'; let name = 'World'; var bar = foo + name; console.log(bar); }
有六个左右的换行符可以让我缩小导致问题的函数或类的范围。我知道这不应该取代开发过程中的测试。