[jQuery] Re: JS Question: How does this jQuery idiom work?

2008-10-16 Thread 703designs
Thanks, I just figured that out last night reading Crockford's "JavaScript: The Good Parts." I considered posting what I learned, then realized that Mike explained it perfectly in the first reply, I was just being dense. Thanks for the explanations! On Oct 16, 10:42 am, Colin Clark <[EMAIL PROTEC

[jQuery] Re: JS Question: How does this jQuery idiom work?

2008-10-16 Thread Colin Clark
Hi, I'll see if I can break down the syntax for you to illustrate what's going on: 1. Define a function. It should take one argument, called $: function ($) { // Do stuff. }; 2. Since the function is anonymous (it doesn't have a name), you need to wrap it in brackets before invoking it:

[jQuery] Re: JS Question: How does this jQuery idiom work?

2008-10-15 Thread 703designs
I still have no idea what's going on syntactically, but now I know what's happening. This reinforced the concept (writes "Poop!" to the screen): (function(poop) { document.write(poop); }) ("Poop!") On Oct 15, 10:00 am, "chris thatcher" <[EMAIL PROTECTED]> wrote: > It's very important becuase

[jQuery] Re: JS Question: How does this jQuery idiom work?

2008-10-15 Thread chris thatcher
It's very important becuase the symbol $ is used by other javascript libraries and it can cause a conflict if you use it outside of the anonymous function. For example another sloppy library might have a global definition var $ = function(){ alert('Not Cool Man!'); }; then if you tried to use

[jQuery] Re: JS Question: How does this jQuery idiom work?

2008-10-15 Thread Mike Alsup
> Plugins are supposed to use this: > > (function($) { >     // Plugin code > > }) (jQuery) > > I know what it does (allows the use of $ within the script), but how > does it actually work? Is it somehow casting the function object as > the jQuery object? It always seemed odd to me, and I haven't