What is this javascript syntax? !function(){}

Possible Duplicate:
What does the exclamation mark do before the function?

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.

Thanks!


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 );

or

(function( $ ) {}( window.jQuery ));
链接地址: http://www.djcxy.com/p/17432.html

上一篇: javascript中的函数是什么?

下一篇: 这是什么JavaScript的语法? !功能(){}