> $(document).ready(function(){
>
> function resizeDiv(that){
> var x = $(that);
> if(x.height() < 600){
> x.css("height","600px");
> }
> };
>
> $("#mydiv").each(function(){resizeDiv(this)});
>
> });
>
> My question: is it better to define this function as above
> and pass "this" or to define an anonymous function within
> the .each statement? I read that the above method only
> has to compile the function once, as opposed to a re-compile
> each time the (anonymous) function runs.
Functions are compiled to bytecode once, not each time they are executed.
Maybe someone was talking about the Function constructor which takes a
string argument and does compile the function each time you execute the
constructor?
> What is the recommend way of doing this?
Well, there's certainly no reason to use *two* functions here. You could
write the code either with a single anonymous function or a single named
function, as shown in Jörn's two examples, whichever you prefer.
-Mike
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/