Agreed with the above and I'll just add these use cases for everyone
to "enjoy"
// filter pattern in loops
for (var i in object) if (object.hasOwnProperty(i)) {
}
for (var i = 0, l = array.length; i < l; i++) if (i % 2) {
}
// nested loops, where your code only affects each item in each value
of a map.
for (var key in map) for (var object = map[key], i = 0, l =
object.length; i < l; i++){
}
The idea being that your curlys are used to demarcate the actionable
code. It's analogous to Python's or Ruby's list comprehension or
inline conditions, respectively.
Olmo
On Feb 21, 1:31 am, אריה גלזר <[email protected]> wrote:
> my rue of thumb is: I use {} whenever i use a line break. when i can keep
> things in one line i find it more readable:
>
> if (check == true) return;
>
> if (check == false){
> //some more complex logic
>
> }
>
> also, whenever nesting other if statements.
>
> this way i don't miss any line break and misinterpretations.
> -----------
> אריה גלזר
> 052-5348-561
> 5561
>
>
>
> On Sat, Feb 20, 2010 at 23:32, Trevor Orr <[email protected]> wrote:
> > This not a MooTools but just a general JavaScript question.
>
> > I was just curious about the usage of the { in if statements.
>
> > Given the 2 blocks below:
>
> > if (variable == 'value')
> > doonestatement;
>
> > OR
>
> > if (variable == 'value') {
> > doonestatement;
> > }
>
> > Is there any benefit to putting the { around the statement to execute if
> > there is only one statement to execute? I have seen code both ways, where
> > there is never a { if there is only one statement and code where there is a
> > { no matter how many statements there are to execute after an if statement.
>
> > Is it just a matter of personal preference or does it provide a speed
> > performance or is there other reasons?