Reasonable to declare the loop-specific variable in What is the syntax? /
in loop?
The first two work both (and do not raise any flag in Google Claus compiler), but only the third person crosses the JC of Crockford, a type of tree. I am reluctant to use it, mostly because it is not compact.
JSLint complains that either
val is a bad variable (when I use
var ), or the declaration should be transferred.
What are the drawbacks for the first or the second option? What should I use? (Example assumes that
str is a declared string and
vals is a declared object)
1 no announcement: For (Val in Wall) {if (vals.hasOwnProperty (val)) {str + = val; }} for different announcements: (var val in vals) {if (vals.hasOwnProperty (val)) { Str = val; }} Out of 3 Loop Wars announcements: var val; For (Val in Wall) {if (vals.hasOwnProperty (val)) {str + = val; }}
Feel free to ignore JSLint. It's more guideline than anything 2 and 3 are functionally similar, either (I use 2) feel free to use. For the first time a global 'val' variable is disclosed, do not do so :)
The reason behind the FII third argument is that inline variable delivery is more difficult than spot / search:
var a, b, c, d, e; At the top of the function.
1 no announcement: For (Val in Wall) {if (vals.hasOwnProperty (val)) {str + = val; }} for different announcements: (var val in vals) {if (vals.hasOwnProperty (val)) { Str = val; }} Out of 3 Loop Wars announcements: var val; For (Val in Wall) {if (vals.hasOwnProperty (val)) {str + = val; }}
Feel free to ignore JSLint. It's more guideline than anything 2 and 3 are functionally similar, either (I use 2) feel free to use. For the first time a global 'val' variable is disclosed, do not do so :)
The reason behind the FII third argument is that inline variable delivery is more difficult than spot / search:
var a, b, c, d, e; At the top of the function.
Comments
Post a Comment