PragueExpat schrieb:
> 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. What is the recommend
> way of doing this?
>
I'd like to quote here:
We *should* forget about small efficiencies, say about 97% of the time:
premature optimizations is the root of all evil. - Donal E. Knuth
We follow two rules in the matter of optimization:
Rule 1. Don't do it.
Rule 2 (for experts only). Don't do it yet - that is, not until you have
perfectly clear and unoptimized solution.
In other words: Write clean and succinct code! Something like this:
$(function(){
function resizeDiv(){
var x = $(this);
if(x.height() < 600){
x.css("height", 600);
}
};
$("#mydiv").each(resizeDiv);
});
And in case you don't use that function anywhere else:
$(function(){
$("#mydiv").each(function(){
var x = $(this);
if(x.height() < 600){
x.css("height",600);
}
}
);
});
The cleaner your code, the easier it is to optimize later, but only
where really appropiate. Firebug's profiler is a great tool for that issue.
--
Jörn Zaefferer
http://bassistance.de
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/