Specifically, this style is called an Immediately Invoked Function
Expression, or IIFE.

https://en.wikipedia.org/wiki/Immediately-invoked_function_expression

On Fri, Jun 10, 2016 at 3:36 AM, ludovic coues <[email protected]> wrote:

> > (function($) {
> >     'use strict';
> >     ....
> > })(django.jQuery);
>
> This syntax is called a closure. First you declare a function so you
> don't contaminate the global scope with your local declared variable.
> Then you execute your function.
> I will assume django.JQuery is the version of JQuery shipped with
> django. Inside the closure, you can refer to it as simply the variable
> $.
>
> I hope that help you.
>
> 2016-06-09 17:06 GMT+02:00 Olivier Dalang <[email protected]>:
> > Hi !
> >
> > I'm using several modules that rely on jQuery, and have some own needs as
> > well :
> >
> >> - admin
> >> - grappelli
> >> - autocomplete light
> >> - session security
> >> ...
> >
> >
> > I also see that there are tons of different variables that reference
> jQuery,
> > defined by theses modules, some of which are the same, and some of which
> are
> > not :
> >
> >> $
> >> jQuery
> >> django.jQuery
> >> grp.jQuery
> >> yl.jQuery
> >> ...
> >
> >
> > I also see django uses this type of syntax which seems to deal about
> > dependecies and clonflicts, but is very cryptic to me (unfortunately
> such a
> > problem is very hard to google) :
> >
> >> /*global DateTimeShortcuts, SelectFilter*/
> >> ...
> >> (function($) {
> >>     'use strict';
> >>     ....
> >> })(django.jQuery);
> >
> >
> >
> > Being a javascript ignorant, up to now, each time I had some javascript
> > exceptions because of jQuery conflicts/undefined, I hacked a bit randomly
> > until the exception disappeared, but I never understood the logic behind
> > this.
> >
> > I'd love some guidance, as my project grows more and more complex, and
> > hacking randomly doesn't shine as a particularly good long term strategy.
> >
> > As partical example, what would be a clean way to add jQuery.AreYouSure
> to
> > the django admin forms ?
> >
> > Is there some documentation or guidelines that explain best practices ?
> Or
> > is it indeed a mess and not just me not understanding ?
> >
> > Thanks !
> >
> > Olivier
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > To post to this group, send email to [email protected].
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/CAExk7p2eggp9rTviqo%2BQ%3DUhprxoLPJ4kWeP7Z_sx0xjZY%3DSVqA%40mail.gmail.com
> .
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEuG%2BTYyB381an2TNW4OiLg3dxfpz0zfcJ4L2D_FxucbKRJ8ZA%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxWTY3%2BaADijByKcdQGafCa%2BxBegMvcCpt5uAtaPWCNxDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to