(function($) {$.fn.METHOD_NAME = function() {FUNCTION_CODE}})
(jQuery);

It's a self-invoking anonymous function passing the global jQuery
object as an argument so that it can be referenced inside the function
as '$'. $.fn is simply equivalent to $.prototype (which ==
jQuery.prototype).

Google "self-invoking anonymous function" and you should get a fair
amount of info.

HTH :)


On May 5, 1:38 pm, kiusau <kiu...@mac.com> wrote:
> On May 5, 11:04 am, Rey Bango <r...@reybango.com> wrote:
>
> > Another option would be to break down in greater detail the areas that
> > you'd like better clarity on. Unfortunately, your original message was
> > quite vague & in terms of helping us optimize our time, you'll need to
> > make the effort to better verbalize what you'd like help with.
>
> All right, please allow me to start over:
>
> QUESTION:  If a lone pair of parentheses can be used to automatically
> call a function, then what does it mean when two pairs are juxtaposed
> in the same statement as follows:  ()(jQuery);?
>
> BACKGROUND:  I have recently learned that any named or anonymous
> JavaScript function can be made into a named jQuery method according
> to the following reassignment
>
> (function($) {$.fn.METHOD_NAME = function() {FUNCTION_CODE}})(jQuery);
>
> A significant portion of this statement I can easily recognize as
> JavaScript -- namely,
>
> $.fn.METHOD_NAME = function() {FUNCTION_CODE};
>
> where function() {FUNCTION_CODE} is an anonymous function assigned to
> the object $.fn as a method named METHOD-NAME.
>
> I can also understand the phrasing
>
> function($) { }
>
> where $ is some parameter assigned to an unnamed function.  If I have
> understood correctly $ is an alias for the jQuery object that is
> passed to this unnamed function.
>
> What I do not understand is the following unusual construction: ()
> (jQuery);
>
> If I remember correctly, a single, empty pair of parentheses can be
> used at the end of a function statement to automatically load a
> function.  I believe the format is:
>
> function( ) {
>   FUNCTION_CODE;}
>
> ();
>
> The construction ()(jQuery); is, however, none of what I recognize as
> JavaScript.  Can someone explain it?
>
> Roddy

Reply via email to