@@ -99,7 +99,7 @@ Using ES6 Blocks:
99
99
``` javascript
100
100
{
101
101
let food = ' Meow Mix' ;
102
- }
102
+ };
103
103
104
104
console .log (food); // Reference Error
105
105
```
@@ -425,7 +425,7 @@ let api = {
425
425
426
426
export default api ;
427
427
428
- /* Which is the same as
428
+ /* Which is the same as
429
429
* export { api as default };
430
430
*/
431
431
```
@@ -725,7 +725,7 @@ React.Component.prototype[refreshComponent] = () => {
725
725
### Symbol.for(key)
726
726
727
727
` Symbol.for(key) ` will create a Symbol that is still immutable and unique, but can be looked up globally.
728
- Two identical calls to ` Symbol.for(key) ` will return the same Symbol instance. NOTE: This is not true for
728
+ Two identical calls to ` Symbol.for(key) ` will return the same Symbol instance. NOTE: This is not true for
729
729
` Symbol(description) ` :
730
730
731
731
``` javascript
@@ -734,8 +734,8 @@ Symbol.for('foo') === Symbol('foo') // false
734
734
Symbol .for (' foo' ) === Symbol .for (' foo' ) // true
735
735
```
736
736
737
- A common use case for Symbols, and in particular with ` Symbol.for(key) ` is for interoperability. This can be
738
- achieved by having your code look for a Symbol member on object arguments from third parties that contain some
737
+ A common use case for Symbols, and in particular with ` Symbol.for(key) ` is for interoperability. This can be
738
+ achieved by having your code look for a Symbol member on object arguments from third parties that contain some
739
739
known interface. For example:
740
740
741
741
``` javascript
@@ -764,7 +764,7 @@ class SomeReadableType {
764
764
```
765
765
766
766
> A notable example of Symbol use for interoperability is ` Symbol.iterator ` which exists on all iterable
767
- types in ES6: Arrays, strings, generators, etc. When called as a method it returns an object with an Iterator
767
+ types in ES6: Arrays, strings, generators, etc. When called as a method it returns an object with an Iterator
768
768
interface.
769
769
770
770
<sup >[ (back to table of contents)] ( #table-of-contents ) </sup >
@@ -894,7 +894,7 @@ let value = map.get(el); // 'reference'
894
894
el .parentNode .removeChild (el);
895
895
el = null ;
896
896
897
- // map is empty, since the element is destroyed
897
+ // map is empty, since the element is destroyed
898
898
```
899
899
900
900
As shown above, once the object is destroyed by the garbage collector,
@@ -1005,9 +1005,9 @@ Promise.all(promises)
1005
1005
1006
1006
## Generators
1007
1007
1008
- Similar to how [ Promises] ( https://github.com/DrkSephy/es6-cheatsheet#promises ) allow us to avoid
1008
+ Similar to how [ Promises] ( https://github.com/DrkSephy/es6-cheatsheet#promises ) allow us to avoid
1009
1009
[ callback hell] ( http://callbackhell.com/ ) , Generators allow us to flatten our code - giving our
1010
- asynchronous code a synchronous feel. Generators are essentially functions which we can
1010
+ asynchronous code a synchronous feel. Generators are essentially functions which we can
1011
1011
[ pause their execution] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield )
1012
1012
and subsequently return the value of an expression.
1013
1013
@@ -1054,9 +1054,9 @@ function* getData() {
1054
1054
```
1055
1055
1056
1056
By the power of ` yield ` , we are guaranteed that ` entry1 ` will have the data needed to be parsed and stored
1057
- in ` data1 ` .
1057
+ in ` data1 ` .
1058
1058
1059
- While generators allow us to write asynchronous code in a synchronous manner, there is no clear
1059
+ While generators allow us to write asynchronous code in a synchronous manner, there is no clear
1060
1060
and easy path for error propagation. As such, as we can augment our generator with Promises:
1061
1061
1062
1062
``` javascript
@@ -1077,12 +1077,12 @@ function iterateGenerator(gen) {
1077
1077
var ret = generator .next ();
1078
1078
if (! ret .done ) {
1079
1079
ret .value .then (iterate);
1080
- }
1081
- })();
1080
+ }
1081
+ })();
1082
1082
}
1083
1083
```
1084
1084
1085
- By augmenting our Generator with Promises, we have a clear way of propagating errors through the use of our
1085
+ By augmenting our Generator with Promises, we have a clear way of propagating errors through the use of our
1086
1086
Promise ` .catch ` and ` reject ` . To use our newly augmented Generator, it is as simple as before:
1087
1087
1088
1088
``` javascript
@@ -1103,25 +1103,25 @@ errors in a nice way, we can actually begin to utilize a simpler construction th
1103
1103
1104
1104
## Async Await
1105
1105
1106
- While this is actually an upcoming ES2016 feature, ` async await ` allows us to perform the same thing we accomplished
1106
+ While this is actually an upcoming ES2016 feature, ` async await ` allows us to perform the same thing we accomplished
1107
1107
using Generators and Promises with less effort:
1108
1108
1109
1109
``` javascript
1110
1110
var request = require (' request' );
1111
-
1111
+
1112
1112
function getJSON (url ) {
1113
1113
return new Promise (function (resolve , reject ) {
1114
1114
request (url, function (error , response , body ) {
1115
1115
resolve (body);
1116
1116
});
1117
1117
});
1118
1118
}
1119
-
1119
+
1120
1120
async function main () {
1121
1121
var data = await getJSON ();
1122
1122
console .log (data); // NOT undefined!
1123
1123
}
1124
-
1124
+
1125
1125
main ();
1126
1126
```
1127
1127
@@ -1149,7 +1149,7 @@ class Employee {
1149
1149
}
1150
1150
1151
1151
set name (newName ) {
1152
- if (newName == this ._name ) {
1152
+ if (newName == this ._name ) {
1153
1153
console .log (' I already have this name.' );
1154
1154
} else if (newName) {
1155
1155
this ._name = newName;
@@ -1162,12 +1162,12 @@ class Employee {
1162
1162
var emp = new Employee (" James Bond" );
1163
1163
1164
1164
// uses the get method in the background
1165
- if (emp .name ) {
1165
+ if (emp .name ) {
1166
1166
console .log (emp .name ); // Mr. JAMES BOND
1167
1167
}
1168
1168
1169
1169
// uses the setter in the background
1170
- emp .name = " Bond 007" ;
1170
+ emp .name = " Bond 007" ;
1171
1171
console .log (emp .name ); // Mr. BOND 007
1172
1172
```
1173
1173
0 commit comments