views:

26

answers:

1

I'm getting a few "Don't make functions within a loop." errors from JSLint, anyone got any tidy suggestions on how to fix this stuff up?

Perhaps my naughtiness is excusable because of my YAHOO dependencies (yd. below)? I can safely say that the only time I've done the following:

for( var i=0; i<FLN.revealers.length;i++ )
{
    var revEl = FLN.revealers[i] ;
    var tag = yd.getElementsBy(function(el){
                return true;
            },'script',revEl );
}

... is when I need to perform an operation on a series of elements nested within a series of elements, to my mind this seems natural. I haven't found any slowness etc in my app, just curious because JSLint hurt my feelings :)

+1  A: 

The simple answer is that in this case the function you're using does not need to be different for each iteration, so you can improve efficiency by using a single function instead:

var f = function(el) {
    return true;
};

for( var i=0; i<FLN.revealers.length;i++ )
{
    var revEl = FLN.revealers[i] ;
    var tag = yd.getElementsBy(f, 'script', revEl);
}
Tim Down