There is a format variant (the variant did not pass the JSLint test) over the curly braces and put the IF statement on the same line.
The benefit of this is that the loop statement becomes more readable (the x is manipulated directly for each element that owns the attribute x).
The result of this is that it takes less indentation to get the loop done:
// call hasOwnProperty () in Object.prototype to filter the prototype property, and avoid having access to other methods of object when enumerating the man's methods. var i, = Object.prototype.hasOwnProperty; for inch Mans) { if (Hasown.call (man,i)) {// filter console.log (i," : " , Man[i]);}
⇓
// Warning: cannot be checked by JSLint var I, = Object.prototype.hasOwnProperty; for inch if (Hasown.call (Man,i)) {// filter console.log (i,":", Man[i]);}
The same if statement also has this kind of ellipsis, I see colleagues write Java write after writing JS also so write,
But there's a problem with writing in Java:
if ()
When you do not use curly braces, there is no declaration, because that involves scopes, and no curly brackets and no scopes.
See the simple question behind: a discussion of if without parentheses
In C, C + + and C # are correct, even in Vs2005 such Java code is correct, because this form of code in different compilation methods will have different interpretations (such as the scope of the form I is default to the IF () {} In the form of the same. Then the form will be correct). From this can be seen,1, when writing code, as far as possible with the specification,2
I think I'd rather not write like this!