Skip to content

Commit 6840250

Browse files
authored
Update javascript.md (#72)
1 parent 24a0f83 commit 6840250

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

wordpress-coding-standards/javascript.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ These rules encourage liberal spacing for improved developer readability. The mi
4949

5050
Whitespace can easily accumulate at the end of a line – avoid this, as trailing whitespace is caught as an error in JSHint. One way to catch whitespace buildup is enabling visible whitespace characters within your text editor.
5151

52-
### Objects
52+
### Object Declarations
5353

5454
Object declarations can be made on a single line if they are short (remember the line length guidelines). When an object declaration is too long to fit on one line, there must be one property per line. Property names only need to be quoted if they are reserved words or contain special characters:
5555

@@ -67,11 +67,11 @@ var arr = [
6767
4,
6868
15,
6969
];
70-
70+
7171
// Acceptable for small objects and arrays
7272
var obj = { ready: 9, when: 4, 'you are': 15 };
7373
var arr = [ 9, 4, 15 ];
74-
74+
7575
// Bad
7676
var obj = { ready: 9,
7777
when: 4, 'you are': 15 };
@@ -85,17 +85,17 @@ Always include extra spaces around elements and arguments:
8585

8686
```javascript
8787
array = [ a, b ];
88-
88+
8989
foo( arg );
90-
90+
9191
foo( 'string', object );
92-
92+
9393
foo( options, object[ property ] );
94-
94+
9595
foo( node, 'property', 2 );
96-
96+
9797
prop = object[ 'default' ];
98-
98+
9999
firstArrayElement = arr[ 0 ];
100100
```
101101

@@ -300,10 +300,10 @@ If an abbreviation or an acronym occurs at the start of a variable name, it must
300300
```javascript
301301
// "Id" is an abbreviation of "Identifier":
302302
const userId = 1;
303-
303+
304304
// "DOM" is an acronym of "Document Object Model":
305305
const currentDOMDocument = window.document;
306-
306+
307307
// Acronyms and abbreviations at the start of a variable name are consistent
308308
// with camelcase rules covering the first letter of a variable or class.
309309
const domDocument = window.document;
@@ -327,7 +327,7 @@ class Earth {
327327
return Earth.humans;
328328
}
329329
}
330-
330+
331331
Earth.humans = [];
332332
```
333333

@@ -345,10 +345,10 @@ Comments come before the code to which they refer, and should always be preceded
345345

346346
```javascript
347347
someStatement();
348-
348+
349349
// Explanation of something complex on the next line
350350
$( 'p' ).doSomething();
351-
351+
352352
// This is a comment that is long enough to warrant being stretched
353353
// over the span of multiple lines.
354354
```
@@ -381,10 +381,11 @@ These are the preferred ways of checking the type of an object:
381381
- Element: `object.nodeType` or `_.isElement( object )`
382382
- null: `object === null`
383383
- null or undefined: `object == null`
384-
- undefined: <ul>- Global Variables: `typeof variable === 'undefined'`
385-
- Local Variables: `variable === undefined`
386-
- Properties: `object.prop === undefined`
387-
- Any of the above: `_.isUndefined( object )` </li></ul>
384+
- undefined:
385+
- Global Variables: `typeof variable === 'undefined'`
386+
- Local Variables: `variable === undefined`
387+
- Properties: `object.prop === undefined`
388+
- Any of the above: `_.isUndefined( object )`
388389

389390
Anywhere Backbone or Underscore are already used, you are encouraged to use [Underscore.js](http://underscorejs.org/#isElement)'s type checking methods over jQuery's.
390391

0 commit comments

Comments
 (0)