[Project_owners] Javascript question

Konstantin Svist fry.kun at gmail.com
Sat Jul 1 11:20:08 EDT 2006


Yes it's global but it doesn't always work out that way.
I usually prefer not to do this - it's not so hard to initialize j 
outside of the loop (and should not be a performance hit either). The 
main reason is that in case this ever comes into question (if 
specification of JS changes to make variables properly scoped), I won't 
have to change my code at all :)

HTH,
Konstantin


Eric H. Jung wrote:
> Hi,
> 
> I know this works in JS:
> 
> for (var i=0,j="foo";i<5; i++) {dump(i);}
> dump(j);
> 
> It breaks typical scoping rules, but is there anything problematic with
> it? Is everything "global" so it doesn't matter if I do this?
> 
> thanks,
> eric
> 
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 


More information about the Project_owners mailing list