JQuery Syntax Brief

I just downloaded the free jQuery Succinctly e-book for free ( here ) from Syncfusion and started looking at examples.

I see a lot of this type of thing:

<script> (function ($)
{
    $('a').mouseenter(
        function () { alert(this.id); });
})(jQuery);
</script>

I am not sure why the author uses this syntax. $Is the object passed into an anonymous function? What for? What is (jQuery)an anonymous function?

Is this just a way to avoid conflicts with other libraries? It seems to me that these examples could be written much "concisely" :)

Thank.

+5
source share
2 answers

It creates a closure where $ === jQuery, even if $.noConflict()used to remove global jQuery $.

$, , , . , , $.

, / , ( var window this)

+7

, jQuery . "". , $ .

+4

All Articles