blob: 946a48a585393dfd2e0bc97d724debf7510cdda0 [file] [log] [blame] [view]
dbeam814fb452016-12-06 22:55:151<!-- Feature template markdown:
scottchen84ef86ca2016-12-06 01:14:532## Header
3
4**Usage Example:**
5
dbeam814fb452016-12-06 22:55:156```js
scottchen84ef86ca2016-12-06 01:14:537
8```
9
10**Documentation:** [link]()
11
12**Discussion Notes / Link to Thread:**
13
14hyphen-hyphen-hyphen (change to actual hyphen)
scottchen84ef86ca2016-12-06 01:14:5315-->
16
scottchen84ef86ca2016-12-06 01:14:5317<style type="text/css">
18 .doc {
19 font-size: 16px;
20 }
21
22 .doc h2[id] {
23 line-height: 20px;
24 font-size: 16px;
25 }
26
27 .doc h2 > code {
28 font-size: 16px;
29 font-weight: bold;
30 }
31
32 .feature-container {
33 background-color: #e8eef7;
34 border: 1px solid #c3d9ff;
35 margin-bottom: 5px;
36 border-radius: 5px;
37 }
38
39 .feature-container > h2 {
40 cursor: pointer;
41 background-color: #c3d9ff;
42 margin: 0;
43 padding: 5px;
44 border-radius: 5px;
45 }
46
47 .feature-container > *:not(h2){
48 display: none;
49 padding: 0px 10px;
50 }
51
52 .feature-container.open > *:not(h2){
53 display: block;
54 }
55</style>
56
57<script>
dbeam814fb452016-12-06 22:55:1558document.addEventListener('DOMContentLoaded', function(event) {
scottchen84ef86ca2016-12-06 01:14:5359 // Move all headers and corresponding contents to an accordion container.
dbeam814fb452016-12-06 22:55:1560 document.querySelectorAll('h2[id]').forEach(function(header) {
scottchen84ef86ca2016-12-06 01:14:5361 var container = document.createElement('div');
62 container.classList.add('feature-container');
63 header.parentNode.insertBefore(container, header);
64
dbeam814fb452016-12-06 22:55:1565 // Add all the following siblings until it hits an <hr>.
66 var el = header;
67 while (el && el.tagName !== 'HR') {
68 var nextEl = el.nextElementSibling;
69 container.append(el);
70 el = nextEl;
scottchen84ef86ca2016-12-06 01:14:5371 }
72
73 // Add handler to open accordion on click.
dbeam814fb452016-12-06 22:55:1574 header.addEventListener('click', function() {
scottchen84ef86ca2016-12-06 01:14:5375 header.parentNode.classList.toggle('open');
76 });
77 });
78
79 // Then remove all <hr>s since everything's accordionized.
dbeam814fb452016-12-06 22:55:1580 document.querySelectorAll('hr').forEach(function(el) {
81 el.parentNode.removeChild(el);
scottchen84ef86ca2016-12-06 01:14:5382 });
83});
84</script>
85
86[TOC]
87
88# ES6 Support In Chromium
89
dbeam7a419032016-12-07 02:13:1890This is a list of [ECMAScript6](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla)
91features allowed in Chromium code.
scottchen84ef86ca2016-12-06 01:14:5392
dbeam7a419032016-12-07 02:13:1893This is **not** a status list of [v8](https://developers.google.com/v8/)'s
94support for language features.
scottchen84ef86ca2016-12-06 01:14:5395
dbeam7a419032016-12-07 02:13:1896> **TBD:** Do we need to differentiate per-project?
97
98> **TBD:** Cross-platform build support? As in: transpilers?
scottchen84ef86ca2016-12-06 01:14:5399
100You can propose changing the status of a feature by sending an email to
101[email protected]. Include a short blurb on what the feature is and why
102you think it should or should not be allowed, along with links to any relevant
103previous discussion. If the list arrives at some consensus, send a codereview
104to change this file accordingly, linking to your discussion thread.
105
dbeam814fb452016-12-06 22:55:15106> Some descriptions and Usage examples are from [kangax](https://kangax.github.io/compat-table/es6/)
107and [http://es6-features.org/](http://es6-features.org/)
scottchen84ef86ca2016-12-06 01:14:53108
109# Allowed Features
110
111The following features are allowed in Chromium development.
112
dbeam1fbecd7c2016-12-22 03:28:42113## `=>` (Arrow Functions)
114
115Arrow functions provide a concise syntax to create a function, and fix a number
116of difficulties with `this` (e.g. eliminating the need to write `const self =
117this`). Particularly useful for nested functions or callbacks.
118
119Prefer arrow functions over `.bind(this)`.
120
121Arrow 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).
127setTimeout(() => {
128 this.doSomething();
129}, 1000); // no need for .bind(this) or const self = this.
130
131// Another example...
132window.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-arrow-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 for
147iOS. There's a presubmit that should warn you about this.
148
149[Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/iJrC4PVSfoU)
150
151---
152
scottchen84ef86ca2016-12-06 01:14:53153## `Promise`
154
dbeam814fb452016-12-06 22:55:15155The Promise object is used for asynchronous computations. A Promise represents a
156value which may be available now, or in the future, or never.
scottchen84ef86ca2016-12-06 01:14:53157
158**Usage Example:**
159
dbeam814fb452016-12-06 22:55:15160```js
161/** @type {!Promise} */
162var fullyLoaded = new Promise(function(resolve) {
163 function isLoaded() { return document.readyState == 'complete'; }
scottchen84ef86ca2016-12-06 01:14:53164
dbeam814fb452016-12-06 22:55:15165 if (isLoaded()) {
166 resolve();
167 } else {
168 document.onreadystatechange = function() {
169 if (isLoaded()) resolve();
170 };
171 }
scottchen84ef86ca2016-12-06 01:14:53172});
dbeam814fb452016-12-06 22:55:15173
174// ... some time later ...
dbeamc5454c2f2016-12-13 21:43:18175fullyLoaded.then(startTheApp).then(maybeShowFirstRun);
scottchen84ef86ca2016-12-06 01:14:53176```
177
dbeam814fb452016-12-06 22:55:15178**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects)
179[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
scottchen84ef86ca2016-12-06 01:14:53180
181**Discussion Notes:** Feature already extensively used prior to creation of
182this document.
183
184---
185
186# Banned Features
187
188The following features are banned for Chromium development.
189
190# Features To Be Discussed
191
192The following features are currently disallowed. See the top of this page on
193how to propose moving a feature from this list into the allowed or banned
194sections.
195
196## `let` (Block-Scoped Variables)
197
dbeam814fb452016-12-06 22:55:15198`let` declares a variable within the scope of a block. This differs from `var`,
199which uses function level scope.
scottchen84ef86ca2016-12-06 01:14:53200
201**Usage Example:**
202
dbeam814fb452016-12-06 22:55:15203```js
204// Scope.
205function varTest() {
206 var x = 1;
207 if (true) {
208 var x = 2; // Same variable!
209 console.log(x); // 2
210 }
211 console.log(x); // 2
scottchen84ef86ca2016-12-06 01:14:53212}
213
dbeam814fb452016-12-06 22:55:15214function letTest() {
215 let x = 1;
216 if (true) {
217 let x = 2; // Different variable.
218 console.log(x); // 2
219 }
220 console.log(x); // 1
scottchen84ef86ca2016-12-06 01:14:53221}
222
dbeam814fb452016-12-06 22:55:15223// Redeclaration throws.
224function f() {
225 var a = 'hello';
226 var a = 'hola'; // No error!
scottchen84ef86ca2016-12-06 01:14:53227
dbeam814fb452016-12-06 22:55:15228 let b = 'world';
229 let b = 'mundo; // TypeError Identifier 'b' has already been declared.
230}
scottchen84ef86ca2016-12-06 01:14:53231```
232
dbeam814fb452016-12-06 22:55:15233**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-let-and-const-declarations)
scottchen84ef86ca2016-12-06 01:14:53234
235**Discussion Notes / Link to Thread:**
236
237---
238
239## `const` (Block-Scoped Constants)
240
241Constants (also known as "immutable variables") are variables which cannot be
242re-assigned new content. Note that if the value is an object, the object itself
243is still mutable.
244
dbeam814fb452016-12-06 22:55:15245Also note that in Chrome, `const` is block scoped like `let`.
scottchen84ef86ca2016-12-06 01:14:53246
247**Usage Example:**
248
dbeam814fb452016-12-06 22:55:15249```js
scottchen84ef86ca2016-12-06 01:14:53250const gravity = 9.81;
dbeam814fb452016-12-06 22:55:15251gravity = 0; // TypeError: Assignment to constant variable.
252gravity === 9.81; // true
scottchen84ef86ca2016-12-06 01:14:53253
dbeam814fb452016-12-06 22:55:15254const frobber = {isFrobbing: true};
255frobber = {isFrobbing: false}; // TypeError: Assignment to constant variable.
256frobber.isFrobbing = false; // Works.
scottchen84ef86ca2016-12-06 01:14:53257```
258
dbeam814fb452016-12-06 22:55:15259**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-let-and-const-declarations)
260
261**See also:** [Object.freeze()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
scottchen84ef86ca2016-12-06 01:14:53262
263**Discussion Notes / Link to Thread:**
264
265---
266
scottchen84ef86ca2016-12-06 01:14:53267## Classes
268
dbeam814fb452016-12-06 22:55:15269OOP-style and boilerplate-free class syntax, including inheritance, `super()`,
scottchen84ef86ca2016-12-06 01:14:53270static members, and getters and setters.
271
272**Usage Example:**
273
dbeam814fb452016-12-06 22:55:15274```js
275class Shape {
276 constructor(x, y) {
277 this.x = x;
278 this.y = y;
279 }
280}
281// Note: let Shape = class {...}; is also valid.
282
scottchen84ef86ca2016-12-06 01:14:53283class Rectangle extends Shape {
dbeam814fb452016-12-06 22:55:15284 constructor(x, y, width, height) {
scottchen84ef86ca2016-12-06 01:14:53285 super(id, x, y);
286 this.width = width;
287 this.height = height;
288 }
dbeam814fb452016-12-06 22:55:15289
290 static goldenRectangle() {
291 var PHI = (1 + Math.sqrt(5)) / 2;
292 return new Rectangle(0, 0, PHI, 1);
scottchen84ef86ca2016-12-06 01:14:53293 }
dbeam814fb452016-12-06 22:55:15294}
scottchen84ef86ca2016-12-06 01:14:53295```
296
dbeam814fb452016-12-06 22:55:15297**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions)
scottchen84ef86ca2016-12-06 01:14:53298
299**Discussion Notes / Link to Thread:**
300
301---
302
303## Block Scope Functions
304
305**Usage Example:**
306
dbeam814fb452016-12-06 22:55:15307```js
scottchen84ef86ca2016-12-06 01:14:53308{
309 function foo() {
310 return 1;
311 }
312 // foo() === 1
313 {
314 function foo() {
315 return 2;
316 }
317 // foo() === 2
318 }
319 // foo() === 1
320}
321```
322
dbeam814fb452016-12-06 22:55:15323**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-functiondeclarationinstantiation)
scottchen84ef86ca2016-12-06 01:14:53324
325**Discussion Notes / Link to Thread:**
326
327---
328
329## Default Function Parameters
330
dbeam814fb452016-12-06 22:55:15331Initialize parameters with default values if no value or `undefined` is passed.
332
scottchen84ef86ca2016-12-06 01:14:53333**Usage Example:**
334
dbeam814fb452016-12-06 22:55:15335```js
336/**
337 * @param {!Element} element An element to hide.
338 * @param {boolean=} animate Whether to animatedly hide |element|.
339 */
340function hide(element, animate=true) {
341 function setHidden() { element.hidden = true; }
342
343 if (animate)
344 element.animate({...}).then(setHidden);
345 else
346 setHidden();
scottchen84ef86ca2016-12-06 01:14:53347}
dbeam814fb452016-12-06 22:55:15348
349hide(document.body); // Animated, animate=true by default.
350hide(document.body, false); // Not animated.
scottchen84ef86ca2016-12-06 01:14:53351```
352
dbeam814fb452016-12-06 22:55:15353**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-functiondeclarationinstantiation)
354[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters)
scottchen84ef86ca2016-12-06 01:14:53355
356**Discussion Notes / Link to Thread:**
357
358---
359
360## Rest Parameters
361
362Aggregation of function arguments into one Array variable.
363
364**Usage Example:**
365
dbeam814fb452016-12-06 22:55:15366```js
367function usesRestParams(a, b, ...theRest) {
368 console.log(a); // 'a'
369 console.log(b); // 'b'
370 console.log(theRest); // [1, 2, 3]
scottchen84ef86ca2016-12-06 01:14:53371}
dbeam814fb452016-12-06 22:55:15372
373usesRestParams('a', 'b', 1, 2, 3);
scottchen84ef86ca2016-12-06 01:14:53374```
375
dbeam814fb452016-12-06 22:55:15376**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions)
scottchen84ef86ca2016-12-06 01:14:53377
378**Discussion Notes / Link to Thread:**
379
380---
381
382## Spread Operators
383
384Spreading the elements from an iterable collection into individual literals as
385function parameters.
386
387**Usage Example:**
388
dbeam814fb452016-12-06 22:55:15389```js
scottchen84ef86ca2016-12-06 01:14:53390// Spreading an Array
dbeam814fb452016-12-06 22:55:15391var params = ['hello', true, 7];
392var other = [1, 2, ...params]; // [1, 2, 'hello', true, 7]
scottchen84ef86ca2016-12-06 01:14:53393
394// Spreading a String
395var str = 'foo';
dbeam814fb452016-12-06 22:55:15396var chars = [...str]; // ['f', 'o', 'o']
scottchen84ef86ca2016-12-06 01:14:53397```
398
dbeam814fb452016-12-06 22:55:15399**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-argument-lists-runtime-semantics-argumentlistevaluation)
scottchen84ef86ca2016-12-06 01:14:53400
401**Discussion Notes / Link to Thread:**
402
403---
404
405## Object Literal Extensions
406
407Convenient new ways for object property definition.
408
409**Usage Example:**
410
dbeam814fb452016-12-06 22:55:15411```js
scottchen84ef86ca2016-12-06 01:14:53412// Computed property name
dbeam814fb452016-12-06 22:55:15413var prop = 'foo';
414var o = {
415 [prop]: 'hey',
416 ['b' + 'ar']: 'there',
417};
418console.log(o); // {foo: 'hey', bar: 'there'}
scottchen84ef86ca2016-12-06 01:14:53419
420// Shorthand property
dbeam814fb452016-12-06 22:55:15421var foo = 1;
422var bar = 2;
423var o = {foo, bar};
424console.log(o); // {foo: 1, bar: 2}
scottchen84ef86ca2016-12-06 01:14:53425
426// Method property
dbeam814fb452016-12-06 22:55:15427var clearSky = {
428 // Basically the same as clouds: function() { return 0; }.
429 clouds() { return 0; },
430 color() { return 'blue'; },
431};
432console.log(clearSky.color()); // 'blue'
433console.log(clearSky.clouds()); // 0
scottchen84ef86ca2016-12-06 01:14:53434```
435
dbeam814fb452016-12-06 22:55:15436**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-object-initialiser)
437[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer)
scottchen84ef86ca2016-12-06 01:14:53438
439**Discussion Notes / Link to Thread:**
440
441---
442
443## Template Literals
444
445Expression interpolation for Strings, with the ability to access raw template
446pieces.
447
448**Usage Example:**
449
dbeam814fb452016-12-06 22:55:15450```js
scottchen84ef86ca2016-12-06 01:14:53451// Simple example
452var greeting = 'hello';
453var myName = {first: 'Foo', last: 'Bar'};
454var message = `${greeting},
455my name is ${myName.first + myName.last}`;
456// message == 'hello,\nmy name is FooBar'
scottchen84ef86ca2016-12-06 01:14:53457```
458
dbeam814fb452016-12-06 22:55:15459**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-template-literals)
scottchen84ef86ca2016-12-06 01:14:53460
461**Discussion Notes / Link to Thread:**
462
463---
464
465## Binary & Octal Literals
466
467**Usage Example:**
468
dbeam814fb452016-12-06 22:55:15469```js
scottchen84ef86ca2016-12-06 01:14:534700b111110111 === 503;
4710o767 === 503;
472```
473
dbeam814fb452016-12-06 22:55:15474**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-literals-numeric-literals)
scottchen84ef86ca2016-12-06 01:14:53475
476**Discussion Notes / Link to Thread:**
477
478---
479
480## `/u` Unicode Regex Literal
481
482**Usage Example:**
483
dbeam814fb452016-12-06 22:55:15484```js
scottchen84ef86ca2016-12-06 01:14:53485'ð ®·'.match(/./u)[0].length === 2;
486```
487
dbeam814fb452016-12-06 22:55:15488**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-get-regexp.prototype.sticky)
scottchen84ef86ca2016-12-06 01:14:53489
490**Discussion Notes / Link to Thread:**
491
492---
493
494## `\u{}` Unicode String
495
496**Usage Example:**
497
dbeam814fb452016-12-06 22:55:15498```js
499'\u{1d306}' == '\ud834\udf06'; // true
scottchen84ef86ca2016-12-06 01:14:53500```
501
dbeam814fb452016-12-06 22:55:15502**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-literals-string-literals)
scottchen84ef86ca2016-12-06 01:14:53503
504**Discussion Notes / Link to Thread:**
505
506---
507
508## `/y` Regex Sticky Matching
509
510Keep the matching position sticky between matches and this way support
dbeam814fb452016-12-06 22:55:15511efficient parsing of arbitrarily long input strings, even with an arbitrary
scottchen84ef86ca2016-12-06 01:14:53512number of distinct regular expressions.
513
514**Usage Example:**
515
dbeam814fb452016-12-06 22:55:15516```js
scottchen84ef86ca2016-12-06 01:14:53517var re = new RegExp('yy', 'y');
518re.lastIndex = 3;
519var result = re.exec('xxxyyxx')[0];
dbeam814fb452016-12-06 22:55:15520result === 'yy' && re.lastIndex === 5; // true
scottchen84ef86ca2016-12-06 01:14:53521```
522
dbeam814fb452016-12-06 22:55:15523**Documentation:** [link](http://es6-features.org/#RegularExpressionStickyMatching)
scottchen84ef86ca2016-12-06 01:14:53524
525**Discussion Notes / Link to Thread:**
526
527---
528
529## Destructuring Assignment
530
531Flexible destructuring of collections or parameters.
532
533**Usage Example:**
534
dbeam814fb452016-12-06 22:55:15535```js
scottchen84ef86ca2016-12-06 01:14:53536// Array
dbeam814fb452016-12-06 22:55:15537var [a, , b] = [1, 2, 3]; // a = 1, b = 3
scottchen84ef86ca2016-12-06 01:14:53538
539// Object
dbeam814fb452016-12-06 22:55:15540var {width, height} = document.body.getBoundingClientRect();
541// width = rect.width, height = rect.height
scottchen84ef86ca2016-12-06 01:14:53542
543// Parameters
dbeam814fb452016-12-06 22:55:15544function f([name, val]) {
545 console.log(name, val); // 'bar', 42
scottchen84ef86ca2016-12-06 01:14:53546}
dbeam814fb452016-12-06 22:55:15547f(['bar', 42, 'extra 1', 'extra 2']); // 'extra 1' and 'extra 2' are ignored.
scottchen84ef86ca2016-12-06 01:14:53548
dbeam814fb452016-12-06 22:55:15549function g({name: n, val: v}) {
550 console.log(n, v); // 'foo', 7
551}
552g({name: 'foo', val: 7});
553
554function h({name, val}) {
555 console.log(name, val); // 'bar', 42
556}
557h({name: 'bar', val: 42});
scottchen84ef86ca2016-12-06 01:14:53558
559```
560
dbeam814fb452016-12-06 22:55:15561**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-destructuring-assignment)
scottchen84ef86ca2016-12-06 01:14:53562
563**Discussion Notes / Link to Thread:**
564
565---
566
567## Modules
568
569Support for exporting/importing values from/to modules without global
570namespace pollution.
571
572**Usage Example:**
573
dbeam814fb452016-12-06 22:55:15574```js
scottchen84ef86ca2016-12-06 01:14:53575// lib/rect.js
576export function getArea() {...};
dbeam814fb452016-12-06 22:55:15577export {width, height, unimportant};
scottchen84ef86ca2016-12-06 01:14:53578
579// app.js
580import {getArea, width, height} from 'lib/rect';
581
582```
583
dbeam814fb452016-12-06 22:55:15584**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-modules)
scottchen84ef86ca2016-12-06 01:14:53585
586**Discussion Notes / Link to Thread:**
587
588---
589
590## Symbol Type
591
592Unique and immutable data type to be used as an identifier for object
593properties.
594
595**Usage Example:**
596
dbeam814fb452016-12-06 22:55:15597```js
scottchen84ef86ca2016-12-06 01:14:53598const foo = Symbol();
599const bar = Symbol();
dbeam814fb452016-12-06 22:55:15600typeof foo === 'symbol'; // true
601typeof bar === 'symbol'; // true
scottchen84ef86ca2016-12-06 01:14:53602let obj = {};
603obj[foo] = 'foo';
604obj[bar] = 'bar';
dbeam814fb452016-12-06 22:55:15605JSON.stringify(obj); // {}
606Object.keys(obj); // []
607Object.getOwnPropertyNames(obj); // []
608Object.getOwnPropertySymbols(obj); // [foo, bar]
scottchen84ef86ca2016-12-06 01:14:53609```
610
dbeam814fb452016-12-06 22:55:15611**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-symbol-constructor)
scottchen84ef86ca2016-12-06 01:14:53612
613**Discussion Notes / Link to Thread:**
614
615---
616
617## `for ...of` Loops
618
dbeam814fb452016-12-06 22:55:15619Convenient operator to iterate over all values in an iterable collection. This
620differs from `for ...in`, which iterates over all iterable properties.
scottchen84ef86ca2016-12-06 01:14:53621
622**Usage Example:**
623
dbeam814fb452016-12-06 22:55:15624```js
625// Given an iterable collection fibonacci numbers...
626for (var n of fibonacci) {
627 console.log(n); // 1, 1, 2, 3, ...
scottchen84ef86ca2016-12-06 01:14:53628}
629```
630
dbeam814fb452016-12-06 22:55:15631**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-for-in-and-for-of-statements)
632[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of)
scottchen84ef86ca2016-12-06 01:14:53633
634**Discussion Notes / Link to Thread:**
635
636---
637
638## Object Static Methods
639
640**Usage Example:**
641
dbeam814fb452016-12-06 22:55:15642```js
scottchen84ef86ca2016-12-06 01:14:53643// Object.assign
dbeamc5454c2f2016-12-13 21:43:18644var o = Object.assign({a:true}, {b:true}, {c:true}); // {a: true, b: true, c: true}
dbeam814fb452016-12-06 22:55:15645'a' in o && 'b' in o && 'c' in o; // true
scottchen84ef86ca2016-12-06 01:14:53646
647// Object.setPrototypeOf
dbeam814fb452016-12-06 22:55:15648Object.setPrototypeOf({}, Array.prototype) instanceof Array; // true
scottchen84ef86ca2016-12-06 01:14:53649
650// Object.is
dbeamc5454c2f2016-12-13 21:43:18651Object.is(null, null) // true
652Object.is(NaN, NaN) // true
653Object.is(-0, +0) // false, btw: -0 === +0 is true
654
scottchen84ef86ca2016-12-06 01:14:53655// Object.getOwnPropertySymbols
656```
657
dbeam814fb452016-12-06 22:55:15658**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-object-constructor)
scottchen84ef86ca2016-12-06 01:14:53659
660**Discussion Notes / Link to Thread:**
661
662---
663
664## String Static & Prototype methods
665
666**Usage Example:**
667
dbeam814fb452016-12-06 22:55:15668```js
scottchen84ef86ca2016-12-06 01:14:53669// String.raw
670// String.fromCodePoint
671
672// String.prototype.codePointAt
673// String.prototype.normalize
674// String.prototype.repeat
675// String.prototype.startsWith
676// String.prototype.endsWith
677// String.prototype.includes
678```
679
dbeam814fb452016-12-06 22:55:15680**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-string-constructor)
scottchen84ef86ca2016-12-06 01:14:53681
682**Discussion Notes / Link to Thread:**
683
684---
685
686## Array Static & Prototype Methods
687
688**Usage Example:**
689
dbeam814fb452016-12-06 22:55:15690```js
scottchen84ef86ca2016-12-06 01:14:53691// Array.from
692// Array.of
693
694// Array.prototype.copyWithin
695// Array.prototype.find
696// Array.prototype.findIndex
697// Array.prototype.fill
698// Array.prototype.keys
699// Array.prototype.values
700// Array.prototype.entries
701```
702
dbeam814fb452016-12-06 22:55:15703**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-array-constructor)
scottchen84ef86ca2016-12-06 01:14:53704
705**Discussion Notes / Link to Thread:**
706
707---
708
709## Number Properties
710
711**Usage Example:**
712
dbeam814fb452016-12-06 22:55:15713```js
scottchen84ef86ca2016-12-06 01:14:53714// Number.isFinite
715// Number.isInteger
716// Number.isSafeInteger
717// Number.isNaN
718// Number.EPSILON
719// Number.MIN_SAFE_INTEGER
720// Number.MAX_SAFE_INTEGER
721```
722
dbeam814fb452016-12-06 22:55:15723**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-isfinite-number)
scottchen84ef86ca2016-12-06 01:14:53724
725**Discussion Notes / Link to Thread:**
726
727---
728
729## Iterators
730
731**Usage Example:**
732
dbeam814fb452016-12-06 22:55:15733```js
scottchen84ef86ca2016-12-06 01:14:53734let fibonacci = {
735 [Symbol.iterator]() {
736 let pre = 0, cur = 1;
737 return {
738 next () {
dbeam814fb452016-12-06 22:55:15739 [pre, cur] = [cur, pre + cur];
740 return {done: false, value: cur};
scottchen84ef86ca2016-12-06 01:14:53741 }
742 };
743 }
744};
745```
746
747**Documentation:** [link]()
748
749**Discussion Notes / Link to Thread:**
750
751---
752
753## Generators
754
755Special iterators with specified pausing points.
756
757**Usage Example:**
758
dbeam814fb452016-12-06 22:55:15759```js
scottchen84ef86ca2016-12-06 01:14:53760function* range(start, end, step) {
761 while (start < end) {
762 yield start;
763 start += step;
764 }
765}
766
767for (let i of range(0, 10, 2)) {
dbeam814fb452016-12-06 22:55:15768 console.log(i); // 0, 2, 4, 6, 8
scottchen84ef86ca2016-12-06 01:14:53769}
770
771```
772
dbeam814fb452016-12-06 22:55:15773**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-generator-function-definitions)
scottchen84ef86ca2016-12-06 01:14:53774
775**Discussion Notes / Link to Thread:**
776
777---
778
779## `Map`
780
dbeam814fb452016-12-06 22:55:15781A simple key/value map in which any value (both objects and primitive values)
782may be used as either a key or a value.
783
scottchen84ef86ca2016-12-06 01:14:53784**Usage Example:**
785
dbeam814fb452016-12-06 22:55:15786```js
scottchen84ef86ca2016-12-06 01:14:53787var map = new Map();
dbeam814fb452016-12-06 22:55:15788map.size === 0; // true
789map.get('foo'); // undefined
scottchen84ef86ca2016-12-06 01:14:53790
dbeam814fb452016-12-06 22:55:15791var key = {};
scottchen84ef86ca2016-12-06 01:14:53792map.set(key, 123);
dbeam814fb452016-12-06 22:55:15793map.size === 1; // true
794map.has(key); // true
795map.get(key); // 123
scottchen84ef86ca2016-12-06 01:14:53796
dbeam814fb452016-12-06 22:55:15797map.delete(key);
798map.has(key); // false
799map.size === 0; // true
scottchen84ef86ca2016-12-06 01:14:53800```
801
dbeam814fb452016-12-06 22:55:15802**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-map-objects)
803[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
scottchen84ef86ca2016-12-06 01:14:53804
805**Discussion Notes / Link to Thread:**
806
807---
808
809## `Set`
810
dbeam814fb452016-12-06 22:55:15811An object that lets you store unique values of any type, whether primitive
812values or object references.
813
scottchen84ef86ca2016-12-06 01:14:53814**Usage Example:**
815
dbeam814fb452016-12-06 22:55:15816```js
scottchen84ef86ca2016-12-06 01:14:53817var set = new Set();
818
819set.add(123);
dbeam814fb452016-12-06 22:55:15820set.size(); // 1
821set.has(123); // true
scottchen84ef86ca2016-12-06 01:14:53822
dbeam814fb452016-12-06 22:55:15823set.add(123);
824set.size(); // 1
scottchen84ef86ca2016-12-06 01:14:53825```
826
dbeam814fb452016-12-06 22:55:15827**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-set-objects)
828[link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
scottchen84ef86ca2016-12-06 01:14:53829
830**Discussion Notes / Link to Thread:**
831
832---
833
834## `WeakMap`
835
836WeakMap does not prevent garbage collection if nothing else refers to an object
837within the collection.
838
839**Usage Example:**
840
dbeam814fb452016-12-06 22:55:15841```js
scottchen84ef86ca2016-12-06 01:14:53842var key = {};
843var weakmap = new WeakMap();
844
845weakmap.set(key, 123);
846
dbeam814fb452016-12-06 22:55:15847weakmap.has(key) && weakmap.get(key) === 123; // true
scottchen84ef86ca2016-12-06 01:14:53848```
849
dbeam814fb452016-12-06 22:55:15850**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-weakmap-objects)
scottchen84ef86ca2016-12-06 01:14:53851
852**Discussion Notes / Link to Thread:**
853
854---
855
856## `WeakSet`
857
858WeakSet does not prevent garbage collection if nothing else refers to an object
859within the collection.
860
861**Usage Example:**
862
dbeam814fb452016-12-06 22:55:15863```js
scottchen84ef86ca2016-12-06 01:14:53864var obj1 = {};
865var weakset = new WeakSet();
866
867weakset.add(obj1);
868weakset.add(obj1);
869
dbeam814fb452016-12-06 22:55:15870weakset.has(obj1); // true
scottchen84ef86ca2016-12-06 01:14:53871```
872
dbeam814fb452016-12-06 22:55:15873**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-weakset-objects)
scottchen84ef86ca2016-12-06 01:14:53874
875**Discussion Notes / Link to Thread:**
876
877---
878
879## Typed Arrays
880
881A lot of new typed Arrays...
882
883**Usage Example:**
884
dbeam814fb452016-12-06 22:55:15885```js
scottchen84ef86ca2016-12-06 01:14:53886new Int8Array();
887new UInt8Array();
dbeam814fb452016-12-06 22:55:15888new UInt8ClampedArray();
889// ... You get the idea. Click on the Documentation link below to see all.
scottchen84ef86ca2016-12-06 01:14:53890```
891
dbeam814fb452016-12-06 22:55:15892**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects)
scottchen84ef86ca2016-12-06 01:14:53893
894**Discussion Notes / Link to Thread:**
895
896---
897
898## `Proxy`
899
900Hooking into runtime-level object meta-operations.
901
902**Usage Example:**
903
dbeam814fb452016-12-06 22:55:15904```js
905var keyTracker = new Proxy({}, {
906 keysCreated: 0,
907
908 get (receiver, key) {
909 if (key in receiver) {
910 console.log('key already exists');
911 } else {
912 ++this.keysCreated;
913 console.log(this.keysCreated + ' keys created!');
914 receiver[key] = true;
915 }
916 },
scottchen84ef86ca2016-12-06 01:14:53917});
dbeam814fb452016-12-06 22:55:15918
919keyTracker.key1; // '1 keys created!'
920keyTracker.key1; // 'key already exists'
921keyTracker.key2; // '2 keys created!'
scottchen84ef86ca2016-12-06 01:14:53922```
923
dbeam814fb452016-12-06 22:55:15924**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots)
scottchen84ef86ca2016-12-06 01:14:53925
926**Discussion Notes / Link to Thread:**
927
928---
929
930## `Reflection`
931
932Make calls corresponding to the object meta-operations.
933
934**Usage Example:**
935
dbeam814fb452016-12-06 22:55:15936```js
937let obj = {a: 1};
938Object.defineProperty(obj, 'b', {value: 2});
scottchen84ef86ca2016-12-06 01:14:53939obj[Symbol('c')] = 3;
dbeam814fb452016-12-06 22:55:15940Reflect.ownKeys(obj); // ['a', 'b', Symbol(c)]
scottchen84ef86ca2016-12-06 01:14:53941```
942
dbeam814fb452016-12-06 22:55:15943**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-reflection)
scottchen84ef86ca2016-12-06 01:14:53944
945**Discussion Notes / Link to Thread:**
946
947---
948
949## Math Methods
950
951A lot of new Math methods.
952
953**Usage Example:**
954
dbeam814fb452016-12-06 22:55:15955```js
scottchen84ef86ca2016-12-06 01:14:53956// See Doc
957```
958
dbeam814fb452016-12-06 22:55:15959**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-math)
scottchen84ef86ca2016-12-06 01:14:53960
961**Discussion Notes / Link to Thread:**
962
963---