Skip to content Skip to sidebar Skip to footer

JQuery's Function($) (jQuery) Syntax

Possible Duplicate: jQuery: What does (function($) {})(jQuery); mean? I stumbled up on the following code (included in one file) but I just cannot understand what it really mean

Solution 1:

This syntax is not particularly special to jquery, it's normal javascript. Here simply function

function ($) {
    // some code here...
}

(note that it takes argument named $) is called with parameter jQuery (which is, obviously, global object of jQuery framework).

This is usually done when there're several js frameworks on one page (jquery, dojo, prototype, etc) which all redefine global variable $. But with this code, inside doSomething1 or doSomething2 you can always call $('.test') and be certain that call will be processed by jquery, not dojo. Because $ is not a global variable in this case, it's function parameter.


Solution 2:

I'm not sure about your question here, but the (function() means it's self-executing,

and you call them by importing the files in the main page and then calling

doSomething1()


Solution 3:

Mostly likely that was jQuery plugin: Plugins/Authoring


Post a Comment for "JQuery's Function($) (jQuery) Syntax"