Thread:Pecoes/@comment-4674838-20121012013714/@comment-4674838-20121017230436

Pecoes wrote: Those two closures look the same to me. The only difference would be which function is on the "outside". The two closures look completely different to me. I feel like my point may be falling on deaf ears, but I'll try to elaborate :)

Pecoes closure, still frame #1
 * 1) I am reading your code. I see window.setTimeout. The next character is a parenthesis, so I can infer that setTimeout is a method, not a property.
 * 2) The very next word is the keyword, . Thus, I am expecting this to be a function definition, and I expect that the code inside of this function will be run after it's called by

Pecoes closure, still frame #2
 * 1) Wait... you tricked me! That wasn't a function declaration, that's a run-immediately function hidden inside of "setTimeout". You're not passing the function... you're passing the return value of the function !!
 * 2) I can't see the actual parameter being passed to  at a glance. Every time I want to know the value being passed to , I am forced to execute the closure, determine the return value, and then go back up one level in the call stack. That's too much work just to see the value being passed to setTimeout.

In sharp contrast, the closure I gave you isn't tricky like that. It starts at the beginning of the line, so it isn't hidden inside anything else. And you can clearly see what is actually being passed as parameter to