Skip to content

Commit 9d99653

Browse files
author
battaglr
committed
2 parents 65ea6a8 + 72ca7c4 commit 9d99653

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Person.prototype.prefixName = function (arr) {
130130
return arr.map(function (character) {
131131
return this.name + character;
132132
}, this);
133-
}
133+
};
134134
```
135135

136136
As well as bind the context:
@@ -144,7 +144,7 @@ Person.prototype.prefixName = function (arr) {
144144
return arr.map(function (character) {
145145
return this.name + character;
146146
}.bind(this));
147-
}
147+
};
148148
```
149149

150150

@@ -157,7 +157,7 @@ function Person(name) {
157157

158158
Person.prototype.prefixName = function (arr) {
159159
return arr.map(character => this.name + character);
160-
}
160+
};
161161
```
162162

163163
> **Best Practice**: Use **Arrow Functions** whenever you need to preserve the lexical value of **this**.
@@ -221,11 +221,11 @@ In ES6, we now have access to a terser implementation:
221221
Using **Template Literals**, we can now construct strings that have special characters in them without needing to escape them explicitly.
222222

223223
```javascript
224-
var text = "This string contains \"double quotes\" which are escaped."
224+
var text = "This string contains \"double quotes\" which are escaped.";
225225
```
226226

227227
```javascript
228-
let text = `This string contains "double quotes" which are escaped.`
228+
let text = `This string contains "double quotes" which are escaped.`;
229229
```
230230

231231
**Template Literals** also support interpolation, which makes the task of concatenating strings and values:
@@ -251,7 +251,7 @@ var text = (
251251
'cat\n' +
252252
'dog\n' +
253253
'nickelodeon'
254-
)
254+
);
255255
```
256256

257257
Or:
@@ -261,7 +261,7 @@ var text = [
261261
'cat',
262262
'dog',
263263
'nickelodeon'
264-
].join('\n')
264+
].join('\n');
265265
```
266266

267267
**Template Literals** will preserve new lines for us without having to explicitly place them in:
@@ -270,15 +270,15 @@ var text = [
270270
let text = ( `cat
271271
dog
272272
nickelodeon`
273-
)
273+
);
274274
```
275275

276276

277277
**Template Literals** can accept expressions, as well:
278278

279279
```javascript
280-
let today = new Date()
281-
let text = `The time and date is ${today.toLocaleString()}`
280+
let today = new Date();
281+
let text = `The time and date is ${today.toLocaleString()}`;
282282
```
283283

284284
<sup>[(back to table of contents)](#table-of-contents)</sup>
@@ -306,13 +306,13 @@ console.log(b); // 2
306306
### Destructuring Objects
307307

308308
```javascript
309-
var luke = { occupation: 'jedi', father: 'anakin' }
309+
var luke = { occupation: 'jedi', father: 'anakin' };
310310
var occupation = luke.occupation; // 'jedi'
311311
var father = luke.father; // 'anakin'
312312
```
313313

314314
```javascript
315-
let luke = { occupation: 'jedi', father: 'anakin' }
315+
let luke = { occupation: 'jedi', father: 'anakin' };
316316
let {occupation, father} = luke;
317317
console.log(occupation); // 'jedi'
318318
console.log(father); // 'anakin'
@@ -327,10 +327,10 @@ Prior to ES6, we used libraries such as [Browserify](http://browserify.org/) to
327327
### Exporting in CommonJS
328328

329329
```javascript
330-
module.exports = 1
331-
module.exports = { foo: 'bar' }
332-
module.exports = ['foo', 'bar']
333-
module.exports = function bar () {}
330+
module.exports = 1;
331+
module.exports = { foo: 'bar' };
332+
module.exports = ['foo', 'bar'];
333+
module.exports = function bar () {};
334334
```
335335

336336
### Exporting in ES6
@@ -382,9 +382,9 @@ function sumThree(a, b, c) {
382382
let api = {
383383
sumTwo,
384384
sumThree
385-
}
385+
};
386386

387-
export default api
387+
export default api;
388388
```
389389

390390
> **Best Practices**: Always use the **export default** method at **the end** of the module. It makes it clear what is being exported, and saves time by having to figure out what name a value was exported as. More so, the common practice in CommonJS modules is to export a single value or object. By sticking to this paradigm, we make our code easily readable and allow ourselves to interpolate between CommonJS and ES6 modules.
@@ -394,15 +394,15 @@ export default api
394394
ES6 provides us with various flavors of importing. We can import an entire file:
395395

396396
```javascript
397-
import `underscore`
397+
import `underscore`;
398398
```
399399

400400
> It is important to note that simply **importing an entire file will execute all code at the top level of that file**.
401401
402402
Similar to Python, we have named imports:
403403

404404
```javascript
405-
import { sumTwo, sumThree } from 'math/addition'
405+
import { sumTwo, sumThree } from 'math/addition';
406406
```
407407

408408
We can also rename the named imports:
@@ -411,13 +411,13 @@ We can also rename the named imports:
411411
import {
412412
sumTwo as addTwoNumbers,
413413
sumThree as sumThreeNumbers
414-
} from 'math/addition'
414+
} from 'math/addition';
415415
```
416416

417417
In addition, we can **import all the things** (also called namespace import):
418418

419419
```javascript
420-
import * as util from 'math/addition'
420+
import * as util from 'math/addition';
421421
```
422422

423423
Lastly, we can import a list of values from a module:
@@ -524,7 +524,7 @@ function initializeCanvas(
524524
We can use the spread operator to pass an array of values to be used as parameters to a function:
525525

526526
```javascript
527-
Math.max(...[-1, 100, 9001, -32]) // 9001
527+
Math.max(...[-1, 100, 9001, -32]); // 9001
528528
```
529529

530530
<sup>[(back to table of contents)](#table-of-contents)</sup>
@@ -558,7 +558,7 @@ Personal.prototype = Object.create(Person.prototype);
558558
Personal.prototype.constructor = Personal;
559559
Personal.prototype.incrementAge = function () {
560560
return Person.prototype.incrementAge.call(this) += 20;
561-
}
561+
};
562562
```
563563

564564
ES6 provides much needed syntactic sugar for doing this under the hood. We can create Classes directly:
@@ -609,7 +609,7 @@ const keyTwo = Symbol();
609609
const object = {};
610610

611611
object[key] = 'Such magic.';
612-
object[keyTwo] = 'Much Uniqueness'
612+
object[keyTwo] = 'Much Uniqueness';
613613

614614
// Two Symbols will never have the same value
615615
>> key === keyTwo
@@ -658,7 +658,7 @@ let map = new Map([
658658
for (let key of map.keys()) {
659659
console.log(typeof key);
660660
// > string, boolean, number, object, function
661-
};
661+
}
662662
```
663663

664664
> **Note**: Using non-primitive values such as functions or objects won't work when testing equality using methods such as `map.get( )`. As such, stick to primitive values such as Strings, Booleans and Numbers.
@@ -792,7 +792,7 @@ var fetchJSON = function(url) {
792792
.done((json) => resolve(json))
793793
.fail((xhr, status, err) => reject(status + err.message));
794794
});
795-
}
795+
};
796796
```
797797

798798
We can also **parallelize** Promises to handle an array of asynchronous operations by using **Promise.all( )**:

0 commit comments

Comments
 (0)