Hi Jonathan,

I think they would both qork exactly the same, BUT this notation...
  (function($){
       ...
   })(jQuery)

Is usually used in plugin authoring to isolate the $ variable in case the
user has decided to use jQuery.noConflict(); - which disables access to
jQuery via $.

So this code is for your personal use (ie.: you're not going to share it
with anyone) and you're not using jQuery.noConflict();, then you don't need
to declare the $ variable at all.

Hope this helps.
Diego

2008/7/3 jfine <[EMAIL PROTECTED]>:

>
> The (rather long) subject line says it all.
>
> This idiom is widely used to avoid having to assume $ == jQuery and at
> the same time avoiding writing jQuery all the time.
>   (function($){
>        ...
>    })(jQuery)
>
> I'm wondering if instead this would work.
>  (function(){
>      var $ = jQuery;
>           ...
>     })()
>
> The reason I ask is that I'd like to shorthand several things in this
> way.  The first method requires me to go down to the end of a (long)
> function body to find out what, say '_' and 'C' really mean (private
> and Constants, say), whereas the second method tells me up front.
>
> I know enough JavaScript to think of this alternative approach, but
> not enough to be sure that it will work in all relevant circumstances.
>
> --
> Jonathan
>



-- 
Cheers,
Diego A.

Reply via email to