Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Readability #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions wordpress-coding-standards/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var arr = [
var obj = { ready: 9, when: 4, 'you are': 15 };
var arr = [ 9, 4, 15 ];

// Bad
// Bad Practice
var obj = { ready: 9,
when: 4, 'you are': 15 };
var arr = [ 9,
Expand Down Expand Up @@ -174,11 +174,11 @@ if ( myFunction() ) {
When a statement is too long to fit on one line, line breaks must occur after an operator.

```javascript
// Bad
// Bad Practice
var html = '<p>The sum of ' + a + ' and ' + b + ' plus ' + c
+ ' is ' + ( a + b + c ) + '</p>';

// Good
// Good Practice
var html = '<p>The sum of ' + a + ' and ' + b + ' plus ' + c +
' is ' + ( a + b + c ) + '</p>';
```
Expand Down Expand Up @@ -235,12 +235,12 @@ Each function should begin with a single comma-delimited `var` statement that de
Assignments within the `var` statement should be listed on individual lines, while declarations can be grouped on a single line. Any additional lines should be indented with an additional tab. Objects and functions that occupy more than a handful of lines should be assigned outside of the `var` statement, to avoid over-indentation.

```javascript
// Good
// Good Practice
var k, m, length,
// Indent subsequent lines by one tab
value = 'WordPress';

// Bad
// Bad Practice
var foo = true;
var bar = false;
var a;
Expand Down Expand Up @@ -495,15 +495,15 @@ prop = object['key-with-hyphens'];
When iterating over a large collection using a `for` loop, it is recommended to store the loop's max value as a variable rather than re-computing the maximum every time:

```javascript
// Good & Efficient
// Good & Efficient Practice
var i, max;

// getItemCount() gets called once
for ( i = 0, max = getItemCount(); i < max; i++ ) {
// Do stuff
}

// Bad & Potentially Inefficient:
// Bad & Potentially Inefficient Practice
// getItemCount() gets called every time
for ( i = 0; i < getItemCount(); i++ ) {
// Do stuff
Expand Down