为什么JavaScript需要以“;”开头? - Why does the JavaScript need to start with “;”?

10/14 08:44
阅读数 0

问题:

I have recently noticed that a lot of JavaScript files on the Web start with a ; 我最近注意到Web上的很多JavaScript文件都以a开头; immediately following the comment section. 紧跟评论部分。

For example, this jQuery plugin's code starts with: 例如, 这个jQuery插件的代码以:

/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008                                      
 .... skipping several lines for brevity...
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){

Why does the file need to start with a ; 为什么文件需要以a开头; ? I see this convention in server-side JavaScript files as well. 我也在服务器端JavaScript文件中看到了这种约定。

What are the advantages and disadvantages of doing this? 这样做的优点和缺点是什么?


解决方案:

参考一: https://en.stackoom.com/question/APYt
参考二: https://stackoom.com/question/APYt
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部