这个javascript语法是什么? !功能(){} [英] What is this javascript syntax? !function(){}
本文介绍了这个javascript语法是什么? !功能(){}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
感叹号在功能之前做了什么?
我今天遇到过这种情况,从未见过:
I came across this today and have never seen before:
!function($) {
//contents removed
}( window.jQuery );
我特别想知道感叹号的作用。有没有任何文件?互联网搜索没有取得好成绩。
I am specifically wondering what the exclamation point does. Is there any documentation on it? Internet searches haven't yielded good results.
谢谢!
推荐答案
函数
语句之前的感叹号会创建函数表达式。如果你想创建一个调用自身的函数,必须表达式而不是声明。
An exclamation mark before a function
statement creates a function expression. If you want to create a function which invokes itself, it must be an expression not a declaration.
通过使用可以达到相同的效果例如, +
字符,或将整个表达式放入括号中。
One could achieve the same result by using a +
character for instance, or putting the whole expression into parenthesis.
+function( $ ) {}( window.jQUery );
或
(function( $ ) {}( window.jQuery ));
这篇关于这个javascript语法是什么? !功能(){}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文