Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: pages/coding-style.html

Issue 29371951: Noissue - Add some more JavaScript coding guidlines (Closed)
Patch Set: Addressed feedback, reordered rules added const rule Created Jan. 18, 2017, 6:23 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pages/coding-style.html
diff --git a/pages/coding-style.html b/pages/coding-style.html
index 553402cd508a746e0587e41d989f54f1b2d588b0..bd96d6c88f20d3a32aa8289146105e7e5bc61833 100644
--- a/pages/coding-style.html
+++ b/pages/coding-style.html
@@ -24,9 +24,20 @@ title=Coding Style
<h2 id="javascript">{{s14 JavaScript}}</h2>
<ul>
<li>{{s15 Follow the Mozilla Coding Style's <a href="https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style#JavaScript_practices">JavaScript practices</a>.}}</li>
- <li>{{s16 Opening braces of object literals in don't go on their own line when that would cause a syntax error.}}</li>
- <li>{{s17 Use <code>bind()</code> to ensure the desired value of the <code>this</code> variable, don’t use temporary variables as a replacement.}}</li>
+ <li>{{javascript-strict Always use <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>.}}</li>
+ <li>{{javascript-opening-braces Opening braces of object literals don't go on their own line when that would cause a syntax error.}}</li>
<li>{{s18 In classes, prefix private functions with a single underscore to make them pseudo-private.}}</li>
+ <li>{{javascript-if-else-braces When an <code><fix>if</fix></code> statement, an <code><fix>else</fix></code> statement or a loop spans over more than one line always enclose it with braces. When an <code><fix>if</fix></code> or <code><fix>else</fix></code> statement uses braces the opposing block should do too.}}</li>
Sebastian Noack 2017/01/18 09:56:20 Perhaps we should put the two rules about braces n
kzar 2017/01/18 10:26:42 Done.
+ <li>{{javascript-object-proto-null Use <code><fix>Object.create</fix></code> to create an object with a specific prototype rather than by specifying or modifying the <code><fix>__proto__</fix></code> property.}}</li>
Sebastian Noack 2017/01/18 09:56:20 As it stands now, this rule is kinda redundant, as
kzar 2017/01/18 10:26:42 Removed.
+ <h3 id="javascript-modern">{{javascript-es6 Modern JavaScript (where supported)}}</h3>
+ <ul>
+ <li>{{javascript-block-scoping Always use <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/block#With_let_and_const">block-scoping</a> (<code><fix>let</fix></code> / <code><fix>const</fix></code>), except when sharing global variables between scripts cannot be avoided.}}</li>
+ <li>{{javascript-const Use <code><fix>const</fix></code> for constant expressions that could as well have been inlined (e.g. static parameters, imported modules, etc.).}}</li>
+ <li>{{javascript-arrow Use the <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow function</a> syntax when passing anonymous functions that don't require the binding of their own <code><fix>this</fix></code> or <code><fix>arguments</fix></code> variables.}}</li>
+ <li>{{javascript-method Use the <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Functions/Method_definitions">method definition shorthand</a> syntax when defining methods on an object.}}</li>
+ <li>{{javascript-for-of When iterating over arrays in the canonical order use the new <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/for...of">for..of</a> syntax if the loop index isn't required. (Rather than using <code><fix>for(;;)</fix></code> or the <code><fix>forEach()</fix></code> method.)}}</li>
Sebastian Noack 2017/01/18 09:56:20 Just because "for..of" is linked now, doesn't mean
Sebastian Noack 2017/01/18 09:56:20 Is it grammatically correct to end the sentence be
kzar 2017/01/18 10:26:42 No idea, how about "As opposed ..."?
kzar 2017/01/18 10:26:42 Done.
+ <li>{{javascript-map-set Use the <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a> or <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set">Set</a> data types rather than misusing plain objects.}}</li>
Sebastian Noack 2017/01/18 09:56:20 I still think think talking about datatypes is ina
kzar 2017/01/18 10:26:42 Done.
+ </ul>
</ul>
<h2 id="html-css">{{html-css HTML and CSS}}</h2>
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld