Home  >  Article  >  Web Front-end  >  jQuery中;function($,undefined) 前面的分号的用处_jquery

jQuery中;function($,undefined) 前面的分号的用处_jquery

WBOY
WBOYOriginal
2016-05-16 16:25:49989browse

;(function($){$.extend($.fn...

一般在一些 JQuery 函数前面有分号,在前面加分号可以有多种用途:

1、防止多文件集成成一个文件后,高压缩出现语法错误。

2、这是一个匿名函数,一般js库都采用这种自执行的匿名函数来保护内部变量 (function(){})()。

3、因为undefined是window的属性,声明为局部变量之后,在函数中如果再有变量与undefined作比较的话,程序就可以不用搜索undefined到window,可以提高程序性能。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn