稍后添加:我想进一步澄清我的担忧。我担心的是没有分号的未缩小代码。 但是缩小代码(单行)中缺少分号怎么办?因为它表示语句的结束。
我也浏览了这个问题的答案https://stackoverflow.com/questions/5840845/reliable-and-convenient-javascript-minifier#=
我也浏览了stephenwlther链接。
但我的担忧仍然没有解决。因为缩小工具会从很多行中删除分号。
检查这个未缩小的代码...
(jQuery)(function ($) {
function statsCount(options) {
var $this = $(this);
options = $.extend({}, options || {}, $this.data('countToOptions') || {});
$this.countTo(options);
} // NUMBERS COUNTER END
function statsAnimate() {
// NUMBERS COUNTER START
$('.numbers').data('countToOptions', {
formatter: function (value, options) {
return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
}
});
// start timer
$('.timer').each(statsCount);
}
if (typeof (CMA) != "undefined" && CMA.elementsAnimation) {
$('.numbers-counter').waypoint(function () {
statsAnimate();
},
{offset: '70%'}
);
} else {
statsAnimate();
}
});
minifier.org 给了我下面的代码....
(jQuery)(function($){function statsCount(options){var $this=$(this);options=$.extend({},options||{},$this.data('countToOptions')||});$this.countTo(options)}function statsAnimate()$('.numbers').data('countToOptions',formatter:function(value,options){return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g,',')}});$('.timer').each(statsCount)}if(typeof(CMA)!="undefined"&&CMA.elementsAnimation){$('.numbers-counter').waypoint(function()statsAnimate()},offset:'70%'})}else{statsAnimate()}})
注意末尾和很多地方都没有分号。
如果这是正确的??
JavaScript 的自动分号插入即使没有换行符也能工作。我不知道您使用的是什么缩小器,但是今天所有常用的缩小器都足够精确,可以在必要时插入分号以保留原始解析,删除不需要的分号。另请参阅https://github.com/standard/standard/blob/caa357395b48bc5e1cced3c85a5eb47bbf4aeac8/RULES.md#helpful-reading。