【发布时间】:2011-01-29 16:57:57
【问题描述】:
我最近注意到 Web 上的许多 JavaScript 文件都以; 开头,紧跟在评论部分之后。
例如,this jQuery plugin's 代码以:
/**
* 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( $ ){
为什么文件需要以; 开头?我在服务器端 JavaScript 文件中也看到了这种约定。
这样做有什么好处和坏处?
【问题讨论】:
标签: javascript jquery jquery-plugins serverside-javascript