In Javascript, what does this syntax mean?

I found this snippet when I looked at jQuery plugins and wondered what it actually does

Skeleton jQuery plugin:

(function($) {
    ... 
})(jQuery); 

And most recently in nettuts :

var STICKIES = (function () {
    ...
}()); 
0
source share
3 answers

This creates an anonymous function and calls it directly: this is equivalent

var fun = function(){};
fun();

jquery , '$'. sekeleton , "$" ( , "$" ), "jQuery", $ = jQuery, .

+7

:

function($) {
    ... 
}

. : (jQuery); jQuery ( $ ).

nettuts .

0

The first function means that $ is being overwritten by jQuery, which is useful if you gave a different "$" value in the script.

0
source

All Articles