相关疑难解决方法(0)

为什么JavaScript需要以";"开头?

我最近注意到,Web上的很多JavaScript文件都是;紧跟在评论部分之后开始的.

例如,这个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( $ ){
Run Code Online (Sandbox Code Playgroud)

为什么文件需要以;?开头?我也在服务器端JavaScript文件中看到了这种约定.

这样做的优点和缺点是什么?

javascript jquery jquery-plugins serverside-javascript

217
推荐指数
3
解决办法
7117
查看次数