I’m a bit confused in how functions operate in javascript. I understand that they’re all objects but how does that change how I would use them as arguments?
For instance, if I’m trying to use a callback function where the 2nd argument is evaluated after 1000ms…
$(this).fadeIn(1000,function(){alert('done fading in');});
Why can’t I achieve the same effect with:
$(this).fadeIn(1000,alert('done fading in'));
If I do, it evaluates both at the same time. That is, (this) element fades in and the alert pops up at the same time.
When I’m calling alert(arg), aren’t I creating a new object which gets passed into fadeIn()?
How exactly does this work?
In this
what does fadeIn() see as its second argument? It’s the result of calling
we are making the call to alert() before calling fadeIn().
In this case
we have an object
which fadeIn() calls at the right time.