Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: docs/es6_chromium.md

Issue 2552173002: ES6 Support: do review comments left on proposed ES6 style guide (Closed)
Patch Set: review Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- This is feature markdown template 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]()
11 11
12 **Discussion Notes / Link to Thread:** 12 **Discussion Notes / Link to Thread:**
13 13
14 hyphen-hyphen-hyphen (change to actual hyphen) 14 hyphen-hyphen-hyphen (change to actual hyphen)
15
16 --> 15 -->
17 16
18
19 <style type="text/css"> 17 <style type="text/css">
20 .doc { 18 .doc {
21 font-size: 16px; 19 font-size: 16px;
22 } 20 }
23 21
24 .doc h2[id] { 22 .doc h2[id] {
25 line-height: 20px; 23 line-height: 20px;
26 font-size: 16px; 24 font-size: 16px;
27 } 25 }
28 26
(...skipping 21 matching lines...) Expand all
50 display: none; 48 display: none;
51 padding: 0px 10px; 49 padding: 0px 10px;
52 } 50 }
53 51
54 .feature-container.open > *:not(h2){ 52 .feature-container.open > *:not(h2){
55 display: block; 53 display: block;
56 } 54 }
57 </style> 55 </style>
58 56
59 <script> 57 <script>
60 document.addEventListener("DOMContentLoaded", function(event) { 58 document.addEventListener('DOMContentLoaded', function(event) {
61 // Move all headers and corresponding contents to an accordion container. 59 // Move all headers and corresponding contents to an accordion container.
62 document.querySelectorAll('h2[id]').forEach(function(header){ 60 document.querySelectorAll('h2[id]').forEach(function(header) {
63 var container = document.createElement('div'); 61 var container = document.createElement('div');
64 container.classList.add('feature-container'); 62 container.classList.add('feature-container');
65 header.parentNode.insertBefore(container, header); 63 header.parentNode.insertBefore(container, header);
66 64
67 // Add all the following siblings until it hits an <hr> 65 // Add all the following siblings until it hits an <hr>.
68 var ele = header; 66 var el = header;
69 while(ele && ele.tagName !== 'HR') { 67 while (el && el.tagName !== 'HR') {
70 var nextEle = ele.nextElementSibling; 68 var nextEl = el.nextElementSibling;
71 container.append(ele); 69 container.append(el);
72 ele = nextEle; 70 el = nextEl;
73 } 71 }
74 72
75 // Add handler to open accordion on click. 73 // Add handler to open accordion on click.
76 header.addEventListener('click', () => { 74 header.addEventListener('click', function() {
77 header.parentNode.classList.toggle('open'); 75 header.parentNode.classList.toggle('open');
78 }); 76 });
79 }); 77 });
80 78
81 // Then remove all <hr>s since everything's accordionized. 79 // Then remove all <hr>s since everything's accordionized.
82 document.querySelectorAll('hr').forEach(function(ele){ 80 document.querySelectorAll('hr').forEach(function(el) {
83 ele.parentNode.removeChild(ele); 81 el.parentNode.removeChild(el);
84 }); 82 });
85 }); 83 });
86 </script> 84 </script>
87 85
88 [TOC] 86 [TOC]
89 87
90 # ES6 Support In Chromium 88 # ES6 Support In Chromium
91 89
92 This is a list of new/updated features in ES6 specs that is being considered to 90 This is a list of new/updated features in ES6 specs that is being considered to
93 be supported for Chromium development. 91 be supported for Chromium development.
94 92
95 >**TBD:** Do we want to differenciate allow/ban status between subprojects? If 93 > **TBD:** Do we want to differenciate allow/ban status between subprojects? If
96 so, how to denote? 94 > so, how to denote?
97 95
98 >**TBD:** Cross platform-build support? 96 > **TBD:** Cross platform-build support?
99 97
100 You can propose changing the status of a feature by sending an email to 98 You can propose changing the status of a feature by sending an email to
101 chromium-dev@chromium.org. Include a short blurb on what the feature is and why 99 chromium-dev@chromium.org. Include a short blurb on what the feature is and why
102 you think it should or should not be allowed, along with links to any relevant 100 you think it should or should not be allowed, along with links to any relevant
103 previous discussion. If the list arrives at some consensus, send a codereview 101 previous discussion. If the list arrives at some consensus, send a codereview
104 to change this file accordingly, linking to your discussion thread. 102 to change this file accordingly, linking to your discussion thread.
105 103
106 >Some descriptions and Usage examples are from [kangax](https://kangax.github. 104 > Some descriptions and Usage examples are from [kangax](https://kangax.github.i o/compat-table/es6/)
107 io/compat-table/es6/) and [http://es6-features.org/](http://es6-features.org/) 105 and [http://es6-features.org/](http://es6-features.org/)
108 106
109 # Allowed Features 107 # Allowed Features
110 108
111 The following features are allowed in Chromium development. 109 The following features are allowed in Chromium development.
112 110
113 ## `Promise` 111 ## `Promise`
114 112
115 Built-in representation of a value that might be determined asynchronously, 113 The Promise object is used for asynchronous computations. A Promise represents a
116 relieving developers from "callback hell". 114 value which may be available now, or in the future, or never.
117 115
118 **Usage Example:** 116 **Usage Example:**
119 117
120 ``` js 118 ```js
121 function promiseA() { 119 /** @type {!Promise} */
122 return new Promise((resolve, reject) => setTimeout(resolve, 100)); 120 var fullyLoaded = new Promise(function(resolve) {
123 } 121 function isLoaded() { return document.readyState == 'complete'; }
124 122
125 function promiseB() { 123 if (isLoaded()) {
126 return new Promise((resolve, reject) => setTimeout(resolve, 200)); 124 resolve();
127 } 125 } else {
126 document.onreadystatechange = function() {
127 if (isLoaded()) resolve();
128 };
129 }
130 });
128 131
129 function promiseC() { 132 // ... some time later ...
130 return new Promise((resolve, reject) => setTimeout(resolve, 300)); 133 loaded.then(startTheApp).then(maybeShowFirstRun);
131 }
132
133 Promise.all([promiseA(), promiseB(), promiseC()]).then(([a, b, c]) => {
134 someFunction(a, b, c);
135 });
136 ``` 134 ```
137 135
138 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 136 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr omise-objects)
139 /#sec-promise-objects) 137 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ Objects/Promise)
140 138
141 **Discussion Notes:** Feature already extensively used prior to creation of 139 **Discussion Notes:** Feature already extensively used prior to creation of
142 this document. 140 this document.
143 141
144 --- 142 ---
145 143
146 # Banned Features 144 # Banned Features
147 145
148 The following features are banned for Chromium development. 146 The following features are banned for Chromium development.
149 147
150 # Features To Be Discussed 148 # Features To Be Discussed
151 149
152 The following features are currently disallowed. See the top of this page on 150 The following features are currently disallowed. See the top of this page on
153 how to propose moving a feature from this list into the allowed or banned 151 how to propose moving a feature from this list into the allowed or banned
154 sections. 152 sections.
155 153
156 ## `let` (Block-Scoped Variables) 154 ## `let` (Block-Scoped Variables)
157 155
158 Declare variable that exists within the block scope. `let` can generally be 156 `let` declares a variable within the scope of a block. This differs from `var`,
159 used to replace `var` but `let` in global scope, unlike `var`, does not 157 which uses function level scope.
160 introduce a property on the global object.
161 158
162 **Usage Example:** 159 **Usage Example:**
163 160
164 ``` js 161 ```js
165 // This will make all buttons output "3". 162 // Scope.
166 for(var i = 0; i < 3; i++) { 163 function varTest() {
167 buttons[i].onclick = function() { 164 var x = 1;
168 console.log(i); 165 if (true) {
169 }; 166 var x = 2; // Same variable!
167 console.log(x); // 2
168 }
169 console.log(x); // 2
170 } 170 }
171 171
172 // This will make buttons output corresponding "i" values. 172 function letTest() {
173 for(let i = 0; i < 3; i++) { 173 let x = 1;
174 buttons[i].onclick = function() { 174 if (true) {
175 console.log(i); 175 let x = 2; // Different variable.
176 }; 176 console.log(x); // 2
177 }
178 console.log(x); // 1
177 } 179 }
178 180
179 var bar = 1; 181 // Redeclaration throws.
180 var bar = 1; // No error thrown. 182 function f() {
183 var a = 'hello';
184 var a = 'hola'; // No error!
181 185
182 let foo = 1; 186 let b = 'world';
183 let foo = 1; // TypeError: Identifier 'foo' has already been declared. 187 let b = 'mundo; // TypeError Identifier 'x' has already been declared.
dpapad 2016/12/06 22:03:04 s/x/b
Dan Beam 2016/12/06 22:25:25 Done.
188 }
184 ``` 189 ```
185 190
186 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 191 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le t-and-const-declarations)
187 /#sec-let-and-const-declarations)
188 192
189 **Discussion Notes / Link to Thread:** 193 **Discussion Notes / Link to Thread:**
190 194
191 --- 195 ---
192 196
193 ## `const` (Block-Scoped Constants) 197 ## `const` (Block-Scoped Constants)
194 198
195 Constants (also known as "immutable variables") are variables which cannot be 199 Constants (also known as "immutable variables") are variables which cannot be
196 re-assigned new content. Note that if the value is an object, the object itself 200 re-assigned new content. Note that if the value is an object, the object itself
197 is still mutable. 201 is still mutable.
198 202
199 `const` has traditionally been supported as a "function scoped" declaration 203 Also note that in Chrome, `const` is block scoped like `let`.
200 like `var` (except in Internet Explorer), however in VMs supporting ES6 `const`
201 is now a block scope declaration.
202 204
203 **Usage Example:** 205 **Usage Example:**
204 206
205 ``` js 207 ```js
206 const gravity = 9.81; 208 const gravity = 9.81;
207 gravity = 0; // TypeError: Assignment to constant variable. 209 gravity = 0; // TypeError: Assignment to constant variable.
210 gravity === 9.81; // true
208 211
209 gravity === 9.81; // true 212 const frobber = {isFrobbing: true};
213 frobber = {isFrobbing: false}; // TypeError: Assignment to constant variable.
214 frobber.isFrobbing = false; // Works.
210 ``` 215 ```
211 216
212 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 217 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le t-and-const-declarations)
213 /#sec-let-and-const-declarations) 218
219 **See also:** [Object.freeze()](https://developer.mozilla.org/en-US/docs/Web/Jav aScript/Reference/Global_Objects/Object/freeze)
214 220
215 **Discussion Notes / Link to Thread:** 221 **Discussion Notes / Link to Thread:**
216 222
217 --- 223 ---
218 224
219 ## `=>` (Arrow Functions) 225 ## `=>` (Arrow Functions)
220 226
221 Arrow functions provide a concise syntax to create a function, and fix a number 227 Arrow functions provide a concise syntax to create a function, and fix a number
222 of difficulties with this (e.g. eliminating the need to write `const self = 228 of difficulties with this (e.g. eliminating the need to write `const self =
223 this`. Particularly useful for nested functions or callbacks. 229 this`. Particularly useful for nested functions or callbacks.
224 230
225 Prefer arrow functions over the function keyword, over `f.bind(this)`, and 231 Prefer arrow functions over the function keyword and over `f.bind(this)`.
dpapad 2016/12/06 22:03:04 Is this comment suggesting that arrow should be pr
Dan Beam 2016/12/06 22:25:25 no, and have removed that wording for now
226 especially over `goog.bind(f, this)`.
227 232
228 Arrow functions has an implicit return when used without a body block. 233 Arrow functions has an implicit return when used without a body block.
229 234
230 **Usage Example:** 235 **Usage Example:**
231 236
232 ``` js 237 ```js
233 // General usage, eliminating need for .bind(this). 238 // General usage, eliminating need for .bind(this).
234 setTimeout(() => { 239 setTimeout(() => {
235 this.doSomething(); 240 this.doSomething();
236 }, 1000); // no need for .bind(this) or const self = this. 241 }, 1000); // no need for .bind(this) or const self = this.
237 242
238 // Another example... 243 // Another example...
239 window.addEventListener('scroll', (event) => { 244 window.addEventListener('scroll', (event) => {
240 this.doSomething(event); 245 this.doSomething(event);
241 }); // no need for .bind(this) or const self = this. 246 }); // no need for .bind(this) or const self = this.
242 247
243 // Implicit return: returns the value if expression not inside a body block. 248 // Implicit return: returns the value if expression not inside a body block.
244 () => 1 // returns 1 249 () => 1 // returns 1.
245 () => {1} // returns undefined - body block does not implicitly return. 250 () => {1} // returns undefined - body block does not implicitly return.
246 () => {return 1;} // returns 1 251 () => {return 1;} // returns 1.
247 ``` 252 ```
248 253
249 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 254 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ar row-function-definitions)
250 /#sec-arrow-function-definitions)
251 255
252 **Discussion Notes / Link to Thread:** 256 **Discussion Notes / Link to Thread:**
253 257
254 --- 258 ---
255 259
256 ## Classes 260 ## Classes
257 261
258 OOP-style and boilerplate-free class syntax, including inheritance, super(), 262 OOP-style and boilerplate-free class syntax, including inheritance, `super()`,
259 static members, and getters and setters. 263 static members, and getters and setters.
260 264
261 **Usage Example:** 265 **Usage Example:**
262 266
263 ``` js 267 ```js
268 class Shape {
269 constructor(x, y) {
270 this.x = x;
271 this.y = y;
272 }
273 }
274 // Note: let Shape = class {...}; is also valid.
275
264 class Rectangle extends Shape { 276 class Rectangle extends Shape {
265 constructor(id, x, y, width, height) { 277 constructor(x, y, width, height) {
266 super(id, x, y); 278 super(id, x, y);
267 this.width = width; 279 this.width = width;
268 this.height = height; 280 this.height = height;
269 } 281 }
270 static defaultRectangle() { 282
271 return new Rectangle('default', 0, 0, 100, 100); 283 static goldenRectangle() {
284 » » var PHI = (1 + Math.sqrt(5)) / 2;
285 return new Rectangle(0, 0, PHI, 1);
272 } 286 }
273 move(x, y) { 287 }
274 this.x = x;
275 this.y = y;
276 }
277 };
278 ``` 288 ```
279 289
280 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 290 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-cl ass-definitions)
281 /#sec-class-definitions)
282 291
283 **Discussion Notes / Link to Thread:** 292 **Discussion Notes / Link to Thread:**
284 293
285 --- 294 ---
286 295
287 ## Block Scope Functions 296 ## Block Scope Functions
288 297
289 **Usage Example:** 298 **Usage Example:**
290 299
291 ``` js 300 ```js
292 { 301 {
293 function foo() { 302 function foo() {
294 return 1; 303 return 1;
295 } 304 }
296 // foo() === 1 305 // foo() === 1
297 { 306 {
298 function foo() { 307 function foo() {
299 return 2; 308 return 2;
300 } 309 }
301 // foo() === 2 310 // foo() === 2
302 } 311 }
303 // foo() === 1 312 // foo() === 1
304 } 313 }
305 ``` 314 ```
306 315
307 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 316 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fu nctiondeclarationinstantiation)
308 /#sec-functiondeclarationinstantiation)
309 317
310 **Discussion Notes / Link to Thread:** 318 **Discussion Notes / Link to Thread:**
311 319
312 --- 320 ---
313 321
314 ## Default Function Parameters 322 ## Default Function Parameters
315 323
324 Initialize parameters with default values if no value or `undefined` is passed.
325
316 **Usage Example:** 326 **Usage Example:**
317 327
318 ``` js 328 ```js
319 function f(x, y = 7, z = 42) { 329 /**
320 return x + y + z; 330 * @param {!Element} element An element to hide.
331 * @param {boolean=} animate Whether to animatedly hide |element|.
332 */
333 function hide(element, animate=true) {
334 function setHidden() { element.hidden = true; }
335
336 if (animate)
337 element.animate({...}).then(setHidden);
338 else
339 setHidden();
321 } 340 }
322 // f(1) === 50; 341
342 hide(document.body); // Animated, animate=true by default.
343 hide(document.body, false); // Not animated.
323 ``` 344 ```
324 345
325 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 346 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fu nctiondeclarationinstantiation)
326 /#sec-functiondeclarationinstantiation) 347 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functio ns/Default_parameters)
327 348
328 **Discussion Notes / Link to Thread:** 349 **Discussion Notes / Link to Thread:**
329 350
330 --- 351 ---
331 352
332 ## Rest Parameters 353 ## Rest Parameters
333 354
334 Aggregation of function arguments into one Array variable. 355 Aggregation of function arguments into one Array variable.
335 356
336 **Usage Example:** 357 **Usage Example:**
337 358
338 ``` js 359 ```js
339 function f(x, y, ...a) { 360 function usesRestParams(a, b, ...theRest) {
340 // for f(1, 2, 3, 4, 5)... 361 console.log(a); // 'a'
341 // x = 1, y = 2 362 console.log(b); // 'b'
342 // a = [3, 4, 5] 363 console.log(theRest); // [1, 2, 3]
343 } 364 }
365
366 usesRestParams('a', 'b', 1, 2, 3);
344 ``` 367 ```
345 368
346 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 369 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fu nction-definitions)
347 /#sec-function-definitions)
348 370
349 **Discussion Notes / Link to Thread:** 371 **Discussion Notes / Link to Thread:**
350 372
351 --- 373 ---
352 374
353 ## Spread Operators 375 ## Spread Operators
354 376
355 Spreading the elements from an iterable collection into individual literals as 377 Spreading the elements from an iterable collection into individual literals as
356 function parameters. 378 function parameters.
357 379
358 **Usage Example:** 380 **Usage Example:**
359 381
360 ``` js 382 ```js
361 // Spreading an Array 383 // Spreading an Array
362 var params = [ 'hello', true, 7 ]; 384 var params = ['hello', true, 7];
363 var other = [ 1, 2, ...params ]; // [ 1, 2, 'hello', true, 7 ] 385 var other = [1, 2, ...params]; // [1, 2, 'hello', true, 7]
364 f(1, 2, ...params) === 9;
365 386
366 // Spreading a String 387 // Spreading a String
367 var str = 'foo'; 388 var str = 'foo';
368 var chars = [ ...str ]; // [ 'f', 'o', 'o' ] 389 var chars = [...str]; // ['f', 'o', 'o']
369 ``` 390 ```
370 391
371 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 392 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ar gument-lists-runtime-semantics-argumentlistevaluation)
372 /#sec-argument-lists-runtime-semantics-argumentlistevaluation)
373 393
374 **Discussion Notes / Link to Thread:** 394 **Discussion Notes / Link to Thread:**
375 395
376 --- 396 ---
377 397
378 ## Object Literal Extensions 398 ## Object Literal Extensions
379 399
380 Convenient new ways for object property definition. 400 Convenient new ways for object property definition.
381 401
382 **Usage Example:** 402 **Usage Example:**
383 403
384 ``` js 404 ```js
385 // Computed property name 405 // Computed property name
386 var x = 'key'; 406 var prop = 'foo';
387 var obj = {[x]: 1}; 407 var o = {
408 [prop]: 'hey',
409 ['b' + 'ar']: 'there',
410 };
411 console.log(o); // {foo: 'hey', bar: 'there'}
388 412
389 // Shorthand property 413 // Shorthand property
390 var obj = {x, y}; //equivalent to {x:x, y:y} 414 var foo = 1;
415 var bar = 2;
416 var o = {foo, bar};
417 console.log(o); // {foo: 1, bar: 2}
391 418
392 // Method property 419 // Method property
393 var obj = { 420 var clearSky = {
394 foo() {...}, 421 // Basically the same as clouds: function() { return 0; }.
395 bar() {...} 422 clouds() { return 0; },
396 } 423 color() { return 'blue'; },
424 };
425 console.log(clearSky.color()); // 'blue'
426 console.log(clearSky.clouds()); // 0
397 ``` 427 ```
398 428
399 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 429 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ob ject-initialiser)
400 /#sec-object-initialiser) 430 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operato rs/Object_initializer)
401 431
402 **Discussion Notes / Link to Thread:** 432 **Discussion Notes / Link to Thread:**
403 433
404 --- 434 ---
405 435
406 ## Template Literals 436 ## Template Literals
407 437
408 Expression interpolation for Strings, with the ability to access raw template 438 Expression interpolation for Strings, with the ability to access raw template
409 pieces. 439 pieces.
410 440
411 **Usage Example:** 441 **Usage Example:**
412 442
413 ``` js 443 ```js
414 // Simple example 444 // Simple example
415 var greeting = 'hello'; 445 var greeting = 'hello';
416 var myName = {first: 'Foo', last: 'Bar'}; 446 var myName = {first: 'Foo', last: 'Bar'};
417 var message = `${greeting}, 447 var message = `${greeting},
418 my name is ${myName.first + myName.last}`; 448 my name is ${myName.first + myName.last}`;
419 // message == 'hello,\nmy name is FooBar' 449 // message == 'hello,\nmy name is FooBar'
420
421 // Custom interpolation
422 function foo (strings, ...values) {
423 // for foo`bar${42}baz`...
424 // strings[0] === 'bar';
425 // strings[1] === 'baz';
426 // values[0] === 42;
427
428 return strings[1] + strings[0] + values[0];
429 }
430
431 var newString = foo`bar${42}baz`; // 'bazbar42'
432 ``` 450 ```
433 451
434 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 452 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-te mplate-literals)
435 /#sec-template-literals)
436 453
437 **Discussion Notes / Link to Thread:** 454 **Discussion Notes / Link to Thread:**
438 455
439 --- 456 ---
440 457
441 ## Binary & Octal Literals 458 ## Binary & Octal Literals
442 459
443 **Usage Example:** 460 **Usage Example:**
444 461
445 ``` js 462 ```js
446 0b111110111 === 503; 463 0b111110111 === 503;
447 0o767 === 503; 464 0o767 === 503;
448 ``` 465 ```
449 466
450 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 467 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-li terals-numeric-literals)
451 /#sec-literals-numeric-literals)
452 468
453 **Discussion Notes / Link to Thread:** 469 **Discussion Notes / Link to Thread:**
454 470
455 --- 471 ---
456 472
457 ## `/u` Unicode Regex Literal 473 ## `/u` Unicode Regex Literal
458 474
459 **Usage Example:** 475 **Usage Example:**
460 476
461 ``` js 477 ```js
462 'ð ®·'.match(/./u)[0].length === 2; 478 'ð ®·'.match(/./u)[0].length === 2;
463 ``` 479 ```
464 480
465 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 481 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ge t-regexp.prototype.sticky)
466 /#sec-get-regexp.prototype.sticky)
467 482
468 **Discussion Notes / Link to Thread:** 483 **Discussion Notes / Link to Thread:**
469 484
470 --- 485 ---
471 486
472 ## `\u{}` Unicode String 487 ## `\u{}` Unicode String
473 488
474 **Usage Example:** 489 **Usage Example:**
475 490
476 ``` js 491 ```js
477 '\u{1d306}' == '\ud834\udf06'; // true 492 '\u{1d306}' == '\ud834\udf06'; // true
478 ``` 493 ```
479 494
480 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 495 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-li terals-string-literals)
481 /#sec-literals-string-literals)
482 496
483 **Discussion Notes / Link to Thread:** 497 **Discussion Notes / Link to Thread:**
484 498
485 --- 499 ---
486 500
487 ## `/y` Regex Sticky Matching 501 ## `/y` Regex Sticky Matching
488 502
489 Keep the matching position sticky between matches and this way support 503 Keep the matching position sticky between matches and this way support
490 efficient parsing of arbitrary long input strings, even with an arbitrary 504 efficient parsing of arbitrarily long input strings, even with an arbitrary
491 number of distinct regular expressions. 505 number of distinct regular expressions.
492 506
493 **Usage Example:** 507 **Usage Example:**
494 508
495 ``` js 509 ```js
496 var re = new RegExp('yy', 'y'); 510 var re = new RegExp('yy', 'y');
497 re.lastIndex = 3; 511 re.lastIndex = 3;
498 var result = re.exec('xxxyyxx')[0]; 512 var result = re.exec('xxxyyxx')[0];
499 result === 'yy' && re.lastIndex === 5; // true 513 result === 'yy' && re.lastIndex === 5; // true
500 ``` 514 ```
501 515
502 **Documentation:** [link](http://es6-features.org 516 **Documentation:** [link](http://es6-features.org/#RegularExpressionStickyMatchi ng)
503 /#RegularExpressionStickyMatching)
504 517
505 **Discussion Notes / Link to Thread:** 518 **Discussion Notes / Link to Thread:**
506 519
507 --- 520 ---
508 521
509 ## Destructuring Assignment 522 ## Destructuring Assignment
510 523
511 Flexible destructuring of collections or parameters. 524 Flexible destructuring of collections or parameters.
512 525
513 **Usage Example:** 526 **Usage Example:**
514 527
515 ``` js 528 ```js
516 // Array 529 // Array
517 var list = [ 1, 2, 3 ]; 530 var [a, , b] = [1, 2, 3]; // a = 1, b = 3
518 var [ a, , b ] = list;
519 // a = 1, b = 3
520 531
521 // Object 532 // Object
522 var {width, height, area: a} = rect; 533 var {width, height} = document.body.getBoundingClientRect();
523 // width = rect.width, height = rect.height, a = rect.area 534 // width = rect.width, height = rect.height
524 535
525 // Parameters 536 // Parameters
526 function f ([ name, val ]) { 537 function f([name, val]) {
527 console.log(name, val); 538 console.log(name, val); // 'bar', 42
528 } 539 }
529 function g ({ name: n, val: v }) { 540 f(['bar', 42, 'extra 1', 'extra 2']); // 'extra 1' and 'extra 2' are ignored.
530 console.log(n, v); 541
542 function g({name: n, val: v}) {
543 console.log(n, v); // 'foo', 7
531 } 544 }
532 function h ({ name, val }) { 545 g({name: 'foo', val: 7});
533 console.log(name, val); 546
547 function h({name, val}) {
548 console.log(name, val); // 'bar', 42
534 } 549 }
535 550 h({name: 'bar', val: 42});
536 f([ 'bar', 42 ]);
537 g({ name: 'foo', val: 7 });
538 h({ name: 'bar', val: 42 });
539 551
540 ``` 552 ```
541 553
542 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 554 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-de structuring-assignment)
543 /#sec-destructuring-assignment)
544 555
545 **Discussion Notes / Link to Thread:** 556 **Discussion Notes / Link to Thread:**
546 557
547 --- 558 ---
548 559
549 ## Modules 560 ## Modules
550 561
551 Support for exporting/importing values from/to modules without global 562 Support for exporting/importing values from/to modules without global
552 namespace pollution. 563 namespace pollution.
553 564
554 **Usage Example:** 565 **Usage Example:**
555 566
556 ``` js 567 ```js
557 // lib/rect.js 568 // lib/rect.js
558 export function getArea() {...}; 569 export function getArea() {...};
559 export { width, height, unimportant }; 570 export {width, height, unimportant};
560 571
561 // app.js 572 // app.js
562 import {getArea, width, height} from 'lib/rect'; 573 import {getArea, width, height} from 'lib/rect';
563 574
564 ``` 575 ```
565 576
566 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 577 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-mo dules)
567 /#sec-modules)
568 578
569 **Discussion Notes / Link to Thread:** 579 **Discussion Notes / Link to Thread:**
570 580
571 --- 581 ---
572 582
573 ## Symbol Type 583 ## Symbol Type
574 584
575 Unique and immutable data type to be used as an identifier for object 585 Unique and immutable data type to be used as an identifier for object
576 properties. 586 properties.
577 587
578 **Usage Example:** 588 **Usage Example:**
579 589
580 ``` js 590 ```js
581 const foo = Symbol(); 591 const foo = Symbol();
582 const bar = Symbol(); 592 const bar = Symbol();
583 typeof foo === 'symbol'; // true 593 typeof foo === 'symbol'; // true
584 typeof bar === 'symbol'; // true 594 typeof bar === 'symbol'; // true
585 let obj = {}; 595 let obj = {};
586 obj[foo] = 'foo'; 596 obj[foo] = 'foo';
587 obj[bar] = 'bar'; 597 obj[bar] = 'bar';
588 JSON.stringify(obj); // {} 598 JSON.stringify(obj); // {}
589 Object.keys(obj); // [] 599 Object.keys(obj); // []
590 Object.getOwnPropertyNames(obj); // [] 600 Object.getOwnPropertyNames(obj); // []
591 Object.getOwnPropertySymbols(obj); // [ foo, bar ] 601 Object.getOwnPropertySymbols(obj); // [foo, bar]
592 ``` 602 ```
593 603
594 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 604 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-sy mbol-constructor)
595 /#sec-symbol-constructor)
596 605
597 **Discussion Notes / Link to Thread:** 606 **Discussion Notes / Link to Thread:**
598 607
599 --- 608 ---
600 609
601 ## `for ...of` Loops 610 ## `for ...of` Loops
602 611
603 Convenient operator to iterate over all values of an iterable object. 612 Convenient operator to iterate over all values in an iterable collection. This
613 differs from `for ...in`, which iterates over all iterable properties.
604 614
605 **Usage Example:** 615 **Usage Example:**
606 616
607 ``` js 617 ```js
608 // Given an iterable collection `fibonacci`... 618 // Given an iterable collection fibonacci numbers...
609 for (let n of fibonacci) { 619 for (var n of fibonacci) {
610 console.log(n); 620 console.log(n); // 1, 1, 2, 3, ...
611 } 621 }
612 ``` 622 ```
613 623
614 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 624 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fo r-in-and-for-of-statements)
615 /#sec-for-in-and-for-of-statements) 625 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Stateme nts/for...of)
616 626
617 **Discussion Notes / Link to Thread:** 627 **Discussion Notes / Link to Thread:**
618 628
619 --- 629 ---
620 630
621 ## Object Static Methods 631 ## Object Static Methods
622 632
623 **Usage Example:** 633 **Usage Example:**
624 634
625 ``` js 635 ```js
626 // Object.assign 636 // Object.assign
627 var o = Object.assign({a:true}, {b:true}, {c:true}); 637 var o = Object.assign({a:true}, {b:true}, {c:true});
628 'a' in o && 'b' in o && 'c' in o; // true 638 'a' in o && 'b' in o && 'c' in o; // true
629 639
630 // Object.setPrototypeOf 640 // Object.setPrototypeOf
631 Object.setPrototypeOf({}, Array.prototype) instanceof Array; //true 641 Object.setPrototypeOf({}, Array.prototype) instanceof Array; // true
632 642
633 // Object.is 643 // Object.is
634 // Object.getOwnPropertySymbols 644 // Object.getOwnPropertySymbols
635 ``` 645 ```
636 646
637 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 647 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr operties-of-the-object-constructor)
638 /#sec-properties-of-the-object-constructor)
639 648
640 **Discussion Notes / Link to Thread:** 649 **Discussion Notes / Link to Thread:**
641 650
642 --- 651 ---
643 652
644 ## String Static & Prototype methods 653 ## String Static & Prototype methods
645 654
646 **Usage Example:** 655 **Usage Example:**
647 656
648 ``` js 657 ```js
649 // String.raw 658 // String.raw
650 // String.fromCodePoint 659 // String.fromCodePoint
651 660
652 // String.prototype.codePointAt 661 // String.prototype.codePointAt
653 // String.prototype.normalize 662 // String.prototype.normalize
654 // String.prototype.repeat 663 // String.prototype.repeat
655 // String.prototype.startsWith 664 // String.prototype.startsWith
656 // String.prototype.endsWith 665 // String.prototype.endsWith
657 // String.prototype.includes 666 // String.prototype.includes
658 ``` 667 ```
659 668
660 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 669 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr operties-of-the-string-constructor)
661 /#sec-properties-of-the-string-constructor)
662 670
663 **Discussion Notes / Link to Thread:** 671 **Discussion Notes / Link to Thread:**
664 672
665 --- 673 ---
666 674
667 ## Array Static & Prototype Methods 675 ## Array Static & Prototype Methods
668 676
669 **Usage Example:** 677 **Usage Example:**
670 678
671 ``` js 679 ```js
672 // Array.from 680 // Array.from
673 // Array.of 681 // Array.of
674 682
675 // Array.prototype.copyWithin 683 // Array.prototype.copyWithin
676 // Array.prototype.find 684 // Array.prototype.find
677 // Array.prototype.findIndex 685 // Array.prototype.findIndex
678 // Array.prototype.fill 686 // Array.prototype.fill
679 // Array.prototype.keys 687 // Array.prototype.keys
680 // Array.prototype.values 688 // Array.prototype.values
681 // Array.prototype.entries 689 // Array.prototype.entries
682 ``` 690 ```
683 691
684 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 692 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr operties-of-the-array-constructor)
685 /#sec-properties-of-the-array-constructor)
686 693
687 **Discussion Notes / Link to Thread:** 694 **Discussion Notes / Link to Thread:**
688 695
689 --- 696 ---
690 697
691 ## Number Properties 698 ## Number Properties
692 699
693 **Usage Example:** 700 **Usage Example:**
694 701
695 ``` js 702 ```js
696 // Number.isFinite 703 // Number.isFinite
697 // Number.isInteger 704 // Number.isInteger
698 // Number.isSafeInteger 705 // Number.isSafeInteger
699 // Number.isNaN 706 // Number.isNaN
700 // Number.EPSILON 707 // Number.EPSILON
701 // Number.MIN_SAFE_INTEGER 708 // Number.MIN_SAFE_INTEGER
702 // Number.MAX_SAFE_INTEGER 709 // Number.MAX_SAFE_INTEGER
703 ``` 710 ```
704 711
705 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 712 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-is finite-number)
706 /#sec-isfinite-number)
707 713
708 **Discussion Notes / Link to Thread:** 714 **Discussion Notes / Link to Thread:**
709 715
710 --- 716 ---
711 717
712 ## Iterators 718 ## Iterators
713 719
714 **Usage Example:** 720 **Usage Example:**
715 721
716 ``` js 722 ```js
717 let fibonacci = { 723 let fibonacci = {
718 [Symbol.iterator]() { 724 [Symbol.iterator]() {
719 let pre = 0, cur = 1; 725 let pre = 0, cur = 1;
720 return { 726 return {
721 next () { 727 next () {
722 [ pre, cur ] = [ cur, pre + cur ]; 728 [pre, cur] = [cur, pre + cur];
723 return { done: false, value: cur }; 729 return {done: false, value: cur};
724 } 730 }
725 }; 731 };
726 } 732 }
727 }; 733 };
728 ``` 734 ```
729 735
730 **Documentation:** [link]() 736 **Documentation:** [link]()
731 737
732 **Discussion Notes / Link to Thread:** 738 **Discussion Notes / Link to Thread:**
733 739
734 --- 740 ---
735 741
736 ## Generators 742 ## Generators
737 743
738 Special iterators with specified pausing points. 744 Special iterators with specified pausing points.
739 745
740 **Usage Example:** 746 **Usage Example:**
741 747
742 ``` js 748 ```js
743 function* range(start, end, step) { 749 function* range(start, end, step) {
744 while (start < end) { 750 while (start < end) {
745 yield start; 751 yield start;
746 start += step; 752 start += step;
747 } 753 }
748 } 754 }
749 755
750 for (let i of range(0, 10, 2)) { 756 for (let i of range(0, 10, 2)) {
751 console.log(i); // 0, 2, 4, 6, 8 757 console.log(i); // 0, 2, 4, 6, 8
752 } 758 }
753 759
754 ``` 760 ```
755 761
756 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 762 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ge nerator-function-definitions)
757 /#sec-generator-function-definitions)
758 763
759 **Discussion Notes / Link to Thread:** 764 **Discussion Notes / Link to Thread:**
760 765
761 --- 766 ---
762 767
763 ## `Map` 768 ## `Map`
764 769
770 A simple key/value map in which any value (both objects and primitive values)
771 may be used as either a key or a value.
772
765 **Usage Example:** 773 **Usage Example:**
766 774
767 ``` js 775 ```js
776 var map = new Map();
777 map.size === 0; // true
778 map.get('foo'); // undefined
779
768 var key = {}; 780 var key = {};
769 var map = new Map(); 781 map.set(key, 123);
782 map.size === 1; // true
783 map.has(key); // true
784 map.get(key); // 123
770 785
771 map.set(key, 123); 786 map.delete(key);
772 787 map.has(key); // false
773 map.has(key) && map.get(key) === 123; // true 788 map.size === 0; // true
774 ``` 789 ```
775 790
776 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 791 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma p-objects)
777 /#sec-map-objects) 792 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ Objects/Map)
778 793
779 **Discussion Notes / Link to Thread:** 794 **Discussion Notes / Link to Thread:**
780 795
781 --- 796 ---
782 797
783 ## `Set` 798 ## `Set`
784 799
800 An object that lets you store unique values of any type, whether primitive
801 values or object references.
802
785 **Usage Example:** 803 **Usage Example:**
786 804
787 ``` js 805 ```js
788 var obj = {};
789 var set = new Set(); 806 var set = new Set();
790 807
791 set.add(123); 808 set.add(123);
809 set.size(); // 1
810 set.has(123); // true
811
792 set.add(123); 812 set.add(123);
793 813 set.size(); // 1
794 set.has(123); // true
795 ``` 814 ```
796 815
797 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 816 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-se t-objects)
798 /#sec-set-objects) 817 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ Objects/Set)
799 818
800 **Discussion Notes / Link to Thread:** 819 **Discussion Notes / Link to Thread:**
801 820
802 --- 821 ---
803 822
804 ## `WeakMap` 823 ## `WeakMap`
805 824
806 WeakMap does not prevent garbage collection if nothing else refers to an object 825 WeakMap does not prevent garbage collection if nothing else refers to an object
807 within the collection. 826 within the collection.
808 827
809 **Usage Example:** 828 **Usage Example:**
810 829
811 ``` js 830 ```js
812 var key = {}; 831 var key = {};
813 var weakmap = new WeakMap(); 832 var weakmap = new WeakMap();
814 833
815 weakmap.set(key, 123); 834 weakmap.set(key, 123);
816 835
817 weakmap.has(key) && weakmap.get(key) === 123; // true 836 weakmap.has(key) && weakmap.get(key) === 123; // true
818 ``` 837 ```
819 838
820 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 839 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-we akmap-objects)
821 /#sec-weakmap-objects)
822 840
823 **Discussion Notes / Link to Thread:** 841 **Discussion Notes / Link to Thread:**
824 842
825 --- 843 ---
826 844
827 ## `WeakSet` 845 ## `WeakSet`
828 846
829 WeakSet does not prevent garbage collection if nothing else refers to an object 847 WeakSet does not prevent garbage collection if nothing else refers to an object
830 within the collection. 848 within the collection.
831 849
832 **Usage Example:** 850 **Usage Example:**
833 851
834 ``` js 852 ```js
835 var obj1 = {}; 853 var obj1 = {};
836 var weakset = new WeakSet(); 854 var weakset = new WeakSet();
837 855
838 weakset.add(obj1); 856 weakset.add(obj1);
839 weakset.add(obj1); 857 weakset.add(obj1);
840 858
841 weakset.has(obj1); // true 859 weakset.has(obj1); // true
842 ``` 860 ```
843 861
844 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 862 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-we akset-objects)
845 /#sec-weakset-objects)
846 863
847 **Discussion Notes / Link to Thread:** 864 **Discussion Notes / Link to Thread:**
848 865
849 --- 866 ---
850 867
851 ## Typed Arrays 868 ## Typed Arrays
852 869
853 A lot of new typed Arrays... 870 A lot of new typed Arrays...
854 871
855 **Usage Example:** 872 **Usage Example:**
856 873
857 ``` js 874 ```js
858 new Int8Array(); 875 new Int8Array();
859 new UInt8Array(); 876 new UInt8Array();
860 new UInt8ClampedArray() 877 new UInt8ClampedArray();
861 // ...You get the idea. Click on the Documentation link below to see all. 878 // ... You get the idea. Click on the Documentation link below to see all.
862 ``` 879 ```
863 880
864 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 881 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ty pedarray-objects)
865 /#sec-typedarray-objects)
866 882
867 **Discussion Notes / Link to Thread:** 883 **Discussion Notes / Link to Thread:**
868 884
869 --- 885 ---
870 886
871 ## `Proxy` 887 ## `Proxy`
872 888
873 Hooking into runtime-level object meta-operations. 889 Hooking into runtime-level object meta-operations.
874 890
875 **Usage Example:** 891 **Usage Example:**
876 892
877 ``` js 893 ```js
878 let target = { 894 var keyTracker = new Proxy({}, {
879 foo: 'Welcome, foo' 895 keysCreated: 0,
880 }; 896
881 let proxy = new Proxy(target, { 897 get (receiver, key) {
882 get (receiver, name) { 898 if (key in receiver) {
883 return name in receiver ? receiver[name] : `Hello, ${name}`; 899 console.log('key already exists');
884 } 900 } else {
901 ++this.keysCreated;
902 console.log(this.keysCreated + ' keys created!');
903 receiver[key] = true;
904 }
905 },
885 }); 906 });
886 proxy.foo === 'Welcome, foo'; // true 907
887 proxy.world === 'Hello, world'; // true 908 keyTracker.key1; // '1 keys created!'
909 keyTracker.key1; // 'key already exists'
910 keyTracker.key2; // '2 keys created!'
888 ``` 911 ```
889 912
890 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 913 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr oxy-object-internal-methods-and-internal-slots)
891 /#sec-proxy-object-internal-methods-and-internal-slots)
892 914
893 **Discussion Notes / Link to Thread:** 915 **Discussion Notes / Link to Thread:**
894 916
895 --- 917 ---
896 918
897 ## `Reflection` 919 ## `Reflection`
898 920
899 Make calls corresponding to the object meta-operations. 921 Make calls corresponding to the object meta-operations.
900 922
901 **Usage Example:** 923 **Usage Example:**
902 924
903 ``` js 925 ```js
904 let obj = { a: 1 }; 926 let obj = {a: 1};
905 Object.defineProperty(obj, 'b', { value: 2 }); 927 Object.defineProperty(obj, 'b', {value: 2});
906 obj[Symbol('c')] = 3; 928 obj[Symbol('c')] = 3;
907 Reflect.ownKeys(obj); // ['a', 'b', Symbol(c)] 929 Reflect.ownKeys(obj); // ['a', 'b', Symbol(c)]
908 ``` 930 ```
909 931
910 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 932 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-re flection)
911 /#sec-reflection)
912 933
913 **Discussion Notes / Link to Thread:** 934 **Discussion Notes / Link to Thread:**
914 935
915 --- 936 ---
916 937
917 ## Math Methods 938 ## Math Methods
918 939
919 A lot of new Math methods. 940 A lot of new Math methods.
920 941
921 **Usage Example:** 942 **Usage Example:**
922 943
923 ``` js 944 ```js
924 // See Doc 945 // See Doc
925 ``` 946 ```
926 947
927 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0 948 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma th)
928 /#sec-math)
929 949
930 **Discussion Notes / Link to Thread:** 950 **Discussion Notes / Link to Thread:**
931 951
932 --- 952 ---
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698