OLD | NEW |
1 <!-- Feature template markdown: | 1 <!-- Feature template markdown: |
2 ## Header | 2 ## Header |
3 | 3 |
4 **Usage Example:** | 4 **Usage Example:** |
5 | 5 |
6 ```js | 6 ```js |
7 | 7 |
8 ``` | 8 ``` |
9 | 9 |
10 **Documentation:** [link]() | 10 **Documentation:** [link]() |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 previous discussion. If the list arrives at some consensus, send a codereview | 103 previous discussion. If the list arrives at some consensus, send a codereview |
104 to change this file accordingly, linking to your discussion thread. | 104 to change this file accordingly, linking to your discussion thread. |
105 | 105 |
106 > Some descriptions and Usage examples are from [kangax](https://kangax.github.i
o/compat-table/es6/) | 106 > Some descriptions and Usage examples are from [kangax](https://kangax.github.i
o/compat-table/es6/) |
107 and [http://es6-features.org/](http://es6-features.org/) | 107 and [http://es6-features.org/](http://es6-features.org/) |
108 | 108 |
109 # Allowed Features | 109 # Allowed Features |
110 | 110 |
111 The following features are allowed in Chromium development. | 111 The following features are allowed in Chromium development. |
112 | 112 |
| 113 ## `=>` (Arrow Functions) |
| 114 |
| 115 Arrow functions provide a concise syntax to create a function, and fix a number |
| 116 of difficulties with `this` (e.g. eliminating the need to write `const self = |
| 117 this`). Particularly useful for nested functions or callbacks. |
| 118 |
| 119 Prefer arrow functions over `.bind(this)`. |
| 120 |
| 121 Arrow functions have an implicit return when used without a body block. |
| 122 |
| 123 **Usage Example:** |
| 124 |
| 125 ```js |
| 126 // General usage, eliminating need for .bind(this). |
| 127 setTimeout(() => { |
| 128 this.doSomething(); |
| 129 }, 1000); // no need for .bind(this) or const self = this. |
| 130 |
| 131 // Another example... |
| 132 window.addEventListener('scroll', (event) => { |
| 133 this.doSomething(event); |
| 134 }); // no need for .bind(this) or const self = this. |
| 135 |
| 136 // Implicit return: returns the value if expression not inside a body block. |
| 137 () => 1 // returns 1. |
| 138 () => {1} // returns undefined - body block does not implicitly return. |
| 139 () => {return 1;} // returns 1. |
| 140 ``` |
| 141 |
| 142 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ar
row-function-definitions) |
| 143 |
| 144 **Discussion Notes / Link to Thread:** |
| 145 |
| 146 **Note**: => does not work in iOS9. Don't use it in code that runs on Chrome fo
r |
| 147 iOS. There's a presubmit that should warn you about this. |
| 148 |
| 149 [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chrom
ium-dev/iJrC4PVSfoU) |
| 150 |
| 151 --- |
| 152 |
113 ## `Promise` | 153 ## `Promise` |
114 | 154 |
115 The Promise object is used for asynchronous computations. A Promise represents a | 155 The Promise object is used for asynchronous computations. A Promise represents a |
116 value which may be available now, or in the future, or never. | 156 value which may be available now, or in the future, or never. |
117 | 157 |
118 **Usage Example:** | 158 **Usage Example:** |
119 | 159 |
120 ```js | 160 ```js |
121 /** @type {!Promise} */ | 161 /** @type {!Promise} */ |
122 var fullyLoaded = new Promise(function(resolve) { | 162 var fullyLoaded = new Promise(function(resolve) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 ``` | 257 ``` |
218 | 258 |
219 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le
t-and-const-declarations) | 259 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le
t-and-const-declarations) |
220 | 260 |
221 **See also:** [Object.freeze()](https://developer.mozilla.org/en-US/docs/Web/Jav
aScript/Reference/Global_Objects/Object/freeze) | 261 **See also:** [Object.freeze()](https://developer.mozilla.org/en-US/docs/Web/Jav
aScript/Reference/Global_Objects/Object/freeze) |
222 | 262 |
223 **Discussion Notes / Link to Thread:** | 263 **Discussion Notes / Link to Thread:** |
224 | 264 |
225 --- | 265 --- |
226 | 266 |
227 ## `=>` (Arrow Functions) | |
228 | |
229 Arrow functions provide a concise syntax to create a function, and fix a number | |
230 of difficulties with `this` (e.g. eliminating the need to write `const self = | |
231 this`). Particularly useful for nested functions or callbacks. | |
232 | |
233 Prefer arrow functions over `.bind(this)`. | |
234 | |
235 Arrow functions have an implicit return when used without a body block. | |
236 | |
237 **Usage Example:** | |
238 | |
239 ```js | |
240 // General usage, eliminating need for .bind(this). | |
241 setTimeout(() => { | |
242 this.doSomething(); | |
243 }, 1000); // no need for .bind(this) or const self = this. | |
244 | |
245 // Another example... | |
246 window.addEventListener('scroll', (event) => { | |
247 this.doSomething(event); | |
248 }); // no need for .bind(this) or const self = this. | |
249 | |
250 // Implicit return: returns the value if expression not inside a body block. | |
251 () => 1 // returns 1. | |
252 () => {1} // returns undefined - body block does not implicitly return. | |
253 () => {return 1;} // returns 1. | |
254 ``` | |
255 | |
256 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ar
row-function-definitions) | |
257 | |
258 **Discussion Notes / Link to Thread:** | |
259 | |
260 --- | |
261 | |
262 ## Classes | 267 ## Classes |
263 | 268 |
264 OOP-style and boilerplate-free class syntax, including inheritance, `super()`, | 269 OOP-style and boilerplate-free class syntax, including inheritance, `super()`, |
265 static members, and getters and setters. | 270 static members, and getters and setters. |
266 | 271 |
267 **Usage Example:** | 272 **Usage Example:** |
268 | 273 |
269 ```js | 274 ```js |
270 class Shape { | 275 class Shape { |
271 constructor(x, y) { | 276 constructor(x, y) { |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 | 954 |
950 ```js | 955 ```js |
951 // See Doc | 956 // See Doc |
952 ``` | 957 ``` |
953 | 958 |
954 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma
th) | 959 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma
th) |
955 | 960 |
956 **Discussion Notes / Link to Thread:** | 961 **Discussion Notes / Link to Thread:** |
957 | 962 |
958 --- | 963 --- |
OLD | NEW |