Skip to content

Commit b39e8b5

Browse files
committed
Merge pull request #1 from bendc/master
update
2 parents 07d7c8d + 9e3cda3 commit b39e8b5

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

Diff for: README.md

+30-25
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ HTML5 provides us with lots of semantic elements aimed to describe precisely the
3030
</main>
3131
```
3232

33-
Make sure you understand the semantic of the elements you're using. It's worse to use a semantic
33+
Make sure you understand the semantics of the elements you're using. It's worse to use a semantic
3434
element in a wrong way than staying neutral.
3535

3636
```html
@@ -62,7 +62,10 @@ Keep your code terse. Forget about your old XHTML habits.
6262
</head>
6363
<body>
6464
<h1>Contact me</h1>
65-
<input type=email placeholder=[email protected] required=required />
65+
<label>
66+
Email address:
67+
<input type=email placeholder=[email protected] required=required />
68+
</label>
6669
<script src=main.js type=text/javascript></script>
6770
</body>
6871
</html>
@@ -75,7 +78,10 @@ Keep your code terse. Forget about your old XHTML habits.
7578
<link rel=stylesheet href=style.css>
7679

7780
<h1>Contact me</h1>
78-
<input type=email placeholder=[email protected] required>
81+
<label>
82+
Email address:
83+
<input type=email placeholder=[email protected] required>
84+
</label>
7985
<script src=main.js></script>
8086
</html>
8187
```
@@ -133,7 +139,7 @@ important factor.
133139
<title>Hello, world.</title>
134140
<p>...</p>
135141

136-
<!-- good-->
142+
<!-- good -->
137143
<!doctype html>
138144
<meta charset=utf-8>
139145
<title>Hello, world.</title>
@@ -161,7 +167,10 @@ div {
161167

162168
### Box model
163169

164-
Don't change the default box model if you can avoid it.
170+
The box model should ideally be the same for the entire document. A global
171+
`* { box-sizing: border-box; }` is fine, but don't change the default box model
172+
on specific elements if you can avoid it.
173+
165174
```css
166175
/* bad */
167176
div {
@@ -233,7 +242,7 @@ sibling combinators.
233242

234243
```css
235244
/* bad */
236-
div:first-of-type :last-chid > p ~ *
245+
div:first-of-type :last-child > p ~ *
237246

238247
/* good */
239248
div:first-of-type .info
@@ -403,22 +412,22 @@ div:hover {
403412

404413
### Units
405414

406-
Use unitless values when you can. Favor pixels over relative units and seconds over
415+
Use unitless values when you can. Favor `rem` if you use relative units. Prefer seconds over
407416
milliseconds.
408417

409418
```css
410419
/* bad */
411420
div {
412421
margin: 0px;
413-
font-size: 0.9rem;
422+
font-size: .9em;
414423
line-height: 22px;
415424
transition: 500ms;
416425
}
417426

418427
/* good */
419428
div {
420429
margin: 0;
421-
font-size: 15px;
430+
font-size: .9rem;
422431
line-height: 1.5;
423432
transition: .5s;
424433
}
@@ -592,11 +601,13 @@ createDivs(5);
592601
const createDivs = howMany => {
593602
if (!howMany) return;
594603
document.body.insertAdjacentHTML("beforeend", "<div></div>");
595-
return createDiv(howMany - 1);
604+
return createDivs(howMany - 1);
596605
};
597606
createDivs(5);
598607
```
599608

609+
Here's a [generic loop function](https://gist.github.com/bendc/6cb2db4a44ec30208e86) making recursion easier to use.
610+
600611
### Arguments
601612

602613
Forget about the `arguments` object. The rest parameter is always a better option because:
@@ -680,21 +691,15 @@ Avoid nesting functions when you don't have to.
680691
Avoid multiple nested function calls. Use composition instead.
681692

682693
```javascript
683-
// bad
684694
const plus1 = a => a + 1;
685695
const mult2 = a => a * 2;
686696

697+
// bad
687698
mult2(plus1(5)); // => 12
688699

689-
690700
// good
691-
const pipeline = (...funcs) =>
692-
val => funcs.reduce((a, b) => b(a), val);
693-
694-
const plus1 = a => a + 1;
695-
const mult2 = a => a * 2;
701+
const pipeline = (...funcs) => val => funcs.reduce((a, b) => b(a), val);
696702
const addThenMult = pipeline(plus1, mult2);
697-
698703
addThenMult(5); // => 12
699704
```
700705

@@ -725,13 +730,12 @@ Favor `const` over `let` and `let` over `var`.
725730

726731
```javascript
727732
// bad
728-
var obj = {};
729-
obj["foo" + "bar"] = "baz";
733+
var me = new Map();
734+
me.set("name", "Ben").set("country", "Belgium");
730735

731736
// good
732-
const obj = {
733-
["foo" + "bar"]: "baz"
734-
};
737+
const me = new Map();
738+
me.set("name", "Ben").set("country", "Belgium");
735739
```
736740

737741
### Conditions
@@ -799,7 +803,7 @@ meSize++;
799803
meSize; // => 3
800804

801805
// good
802-
const me = Map();
806+
const me = new Map();
803807
me.set("name", "Ben");
804808
me.set("age", 30);
805809
me.size; // => 2
@@ -809,7 +813,8 @@ me.size; // => 3
809813

810814
### Curry
811815

812-
Currying might have its place in other languages, but avoid it in JavaScript. It makes your code harder to read by introducing a foreign paradigm while the appropriate use cases are extremely unusual.
816+
Currying is a powerful but foreign paradigm for many developers. Don't abuse it as its appropriate
817+
use cases are fairly unusual.
813818

814819
```javascript
815820
// bad

0 commit comments

Comments
 (0)