On Mon, Jun 13, 2011 at 1:13 PM, Matthew Bramer <[email protected]> wrote:

> I read this code and see there is one giant variable that starts with a
> self-executing function.
>


> Why is the variable set to run a function automatically in a self-executing
> fashion?
>

Rather than self-executing function, I recommend following what many are
today and calling this pattern an IIFE (Immediately-Invoked Function
Expression). See
http://benalman.com/news/2010/11/immediately-invoked-function-expression/and
http://stackoverflow.com/questions/3720283/what-is-this-practice-called-in-javascript#answer-4539925

- Richard


> What would be the difference if the variable just equaled a function?
> var hackerNews = function( $, undefined ) {
> //stuff
> };
>
> *Also towards the end of the function there is a return pub; statement. I
> can decipher this code as allowing hackerNews to gain access to the methods
> within pub, but why is the code structured like this? Being very new to
> JavaScript, I don't know what this is doing for me as a coder. The code
> looks great, but why is it structured like this and where can I find some
> documentation on why/when/how to use these techniques?*
> *
> *
> *Cheers,*
> *Matt*
> *@iOnline247*
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to