mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
(Coding Convention) Use stacked else/catch
clauses.
This commit is contained in:
@ -87,6 +87,29 @@ if (true)
|
|||||||
|
|
||||||
Also, notice the use of whitespace before and after the condition statement.
|
Also, notice the use of whitespace before and after the condition statement.
|
||||||
|
|
||||||
|
Follow the JavaScript convention of stacking `else/catch` clauses on the same line as the previous closing brace.
|
||||||
|
|
||||||
|
*Right:*
|
||||||
|
|
||||||
|
~~~ {.javascript}
|
||||||
|
if (i % 2 === 0) {
|
||||||
|
console.log('even');
|
||||||
|
} else {
|
||||||
|
console.log('odd');
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
|
*Wrong:*
|
||||||
|
|
||||||
|
~~~ {.javascript}
|
||||||
|
if (i % 2 === 0) {
|
||||||
|
console.log('even');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('odd');
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
## Variable declarations
|
## Variable declarations
|
||||||
|
|
||||||
Declare one variable per var statement. Try to put those declarations at the beginning of each scope.
|
Declare one variable per var statement. Try to put those declarations at the beginning of each scope.
|
||||||
|
Reference in New Issue
Block a user