> This doesn't do too much to demystify anything, imo.
>
> > Now how that works... I have no idea, but I do believe that it's more
> aesthetic and so that's how I write my code. I won't argue if you feel
> differently.
>

I suppose I should have been more specific:

This is an error foo():

    function () {} ()

This is not (foo)()

    (function () {})()

This is not (foo())

    (function () {}())

So foo() is NOT identical to (foo)() where foo is function () {}.



>
> It works because (foo)() is identical to foo().
>


> > The only reason that that even works at all is because there's magic
> going on behind the scenes that hoists the anonymous function up to the top
> (just like with variables) and then calls that function reference.
>
> What am I reading? Function expression are not hoisted.
>

var foo = function () {};

foo gets hoisted



function foo() {};

foo gets hoisted



for () {
  x = function () { console.log(i) };
}

What actually happens is this

function something() {console.log};
for () {
  x = something;
}

I probably could word that better since that's not technically "hoisting",
but in essence  it's still hoisting. The creation of the function is pulled
out of the loop in the same way `var x` would get pulled out and only the
reference remains.

Also setTimeout() takes optional parameters to pass to the callback:
>
> setTimeout(function(a) { console.log(a) }, 0, 'hello')
> hello
>

Well, duh. Anyone with years of JavaScript experience knows that!

However, years of wretched online tutorials do not. I agree that it's a
good solution (and I should probably show that as an alternate way to do
it. However, a common solution is to through in the IIFE.


> Also there's Function.prototype.bind()
>

Also something I might include when I go back and edit.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to