dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 1 | <!-- Feature template markdown: |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 2 | ## Header |
| 3 | |
| 4 | **Usage Example:** |
| 5 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 6 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 7 | |
| 8 | ``` |
| 9 | |
| 10 | **Documentation:** [link]() |
| 11 | |
| 12 | **Discussion Notes / Link to Thread:** |
| 13 | |
| 14 | hyphen-hyphen-hyphen (change to actual hyphen) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 15 | --> |
| 16 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 17 | <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> |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 58 | document.addEventListener('DOMContentLoaded', function(event) { |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 59 | // Move all headers and corresponding contents to an accordion container. |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 60 | document.querySelectorAll('h2[id]').forEach(function(header) { |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 61 | var container = document.createElement('div'); |
| 62 | container.classList.add('feature-container'); |
| 63 | header.parentNode.insertBefore(container, header); |
| 64 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 65 | // 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; |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | // Add handler to open accordion on click. |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 74 | header.addEventListener('click', function() { |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 75 | header.parentNode.classList.toggle('open'); |
| 76 | }); |
| 77 | }); |
| 78 | |
| 79 | // Then remove all <hr>s since everything's accordionized. |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 80 | document.querySelectorAll('hr').forEach(function(el) { |
| 81 | el.parentNode.removeChild(el); |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 82 | }); |
| 83 | }); |
| 84 | </script> |
| 85 | |
| 86 | [TOC] |
| 87 | |
| 88 | # ES6 Support In Chromium |
| 89 | |
dbeam | 7a41903 | 2016-12-07 02:13:18 | [diff] [blame] | 90 | This is a list of [ECMAScript6](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla) |
| 91 | features allowed in Chromium code. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 92 | |
dbeam | 7a41903 | 2016-12-07 02:13:18 | [diff] [blame] | 93 | This is **not** a status list of [v8](https://developers.google.com/v8/)'s |
| 94 | support for language features. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 95 | |
dbeam | 7a41903 | 2016-12-07 02:13:18 | [diff] [blame] | 96 | > **TBD:** Do we need to differentiate per-project? |
| 97 | |
| 98 | > **TBD:** Cross-platform build support? As in: transpilers? |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 99 | |
| 100 | You 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 |
| 102 | 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 |
| 104 | to change this file accordingly, linking to your discussion thread. |
| 105 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 106 | > Some descriptions and Usage examples are from [kangax](https://kangax.github.io/compat-table/es6/) |
| 107 | and [http://es6-features.org/](http://es6-features.org/) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 108 | |
| 109 | # Allowed Features |
| 110 | |
| 111 | The following features are allowed in Chromium development. |
| 112 | |
dbeam | 1fbecd7c | 2016-12-22 03:28:42 | [diff] [blame] | 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-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 |
| 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/chromium-dev/iJrC4PVSfoU) |
| 150 | |
| 151 | --- |
| 152 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 153 | ## `Promise` |
| 154 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 155 | The Promise object is used for asynchronous computations. A Promise represents a |
| 156 | value which may be available now, or in the future, or never. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 157 | |
| 158 | **Usage Example:** |
| 159 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 160 | ```js |
| 161 | /** @type {!Promise} */ |
| 162 | var fullyLoaded = new Promise(function(resolve) { |
| 163 | function isLoaded() { return document.readyState == 'complete'; } |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 164 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 165 | if (isLoaded()) { |
| 166 | resolve(); |
| 167 | } else { |
| 168 | document.onreadystatechange = function() { |
| 169 | if (isLoaded()) resolve(); |
| 170 | }; |
| 171 | } |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 172 | }); |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 173 | |
| 174 | // ... some time later ... |
dbeam | c5454c2f | 2016-12-13 21:43:18 | [diff] [blame] | 175 | fullyLoaded.then(startTheApp).then(maybeShowFirstRun); |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 176 | ``` |
| 177 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 178 | **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) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 180 | |
| 181 | **Discussion Notes:** Feature already extensively used prior to creation of |
| 182 | this document. |
| 183 | |
| 184 | --- |
| 185 | |
| 186 | # Banned Features |
| 187 | |
| 188 | The following features are banned for Chromium development. |
| 189 | |
| 190 | # Features To Be Discussed |
| 191 | |
| 192 | The following features are currently disallowed. See the top of this page on |
| 193 | how to propose moving a feature from this list into the allowed or banned |
| 194 | sections. |
| 195 | |
| 196 | ## `let` (Block-Scoped Variables) |
| 197 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 198 | `let` declares a variable within the scope of a block. This differs from `var`, |
| 199 | which uses function level scope. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 200 | |
| 201 | **Usage Example:** |
| 202 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 203 | ```js |
| 204 | // Scope. |
| 205 | function 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 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 212 | } |
| 213 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 214 | function 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 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 221 | } |
| 222 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 223 | // Redeclaration throws. |
| 224 | function f() { |
| 225 | var a = 'hello'; |
| 226 | var a = 'hola'; // No error! |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 227 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 228 | let b = 'world'; |
| 229 | let b = 'mundo; // TypeError Identifier 'b' has already been declared. |
| 230 | } |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 231 | ``` |
| 232 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 233 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-let-and-const-declarations) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 234 | |
| 235 | **Discussion Notes / Link to Thread:** |
| 236 | |
| 237 | --- |
| 238 | |
| 239 | ## `const` (Block-Scoped Constants) |
| 240 | |
| 241 | Constants (also known as "immutable variables") are variables which cannot be |
| 242 | re-assigned new content. Note that if the value is an object, the object itself |
| 243 | is still mutable. |
| 244 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 245 | Also note that in Chrome, `const` is block scoped like `let`. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 246 | |
| 247 | **Usage Example:** |
| 248 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 249 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 250 | const gravity = 9.81; |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 251 | gravity = 0; // TypeError: Assignment to constant variable. |
| 252 | gravity === 9.81; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 253 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 254 | const frobber = {isFrobbing: true}; |
| 255 | frobber = {isFrobbing: false}; // TypeError: Assignment to constant variable. |
| 256 | frobber.isFrobbing = false; // Works. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 257 | ``` |
| 258 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 259 | **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) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 262 | |
| 263 | **Discussion Notes / Link to Thread:** |
| 264 | |
| 265 | --- |
| 266 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 267 | ## Classes |
| 268 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 269 | OOP-style and boilerplate-free class syntax, including inheritance, `super()`, |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 270 | static members, and getters and setters. |
| 271 | |
| 272 | **Usage Example:** |
| 273 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 274 | ```js |
| 275 | class Shape { |
| 276 | constructor(x, y) { |
| 277 | this.x = x; |
| 278 | this.y = y; |
| 279 | } |
| 280 | } |
| 281 | // Note: let Shape = class {...}; is also valid. |
| 282 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 283 | class Rectangle extends Shape { |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 284 | constructor(x, y, width, height) { |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 285 | super(id, x, y); |
| 286 | this.width = width; |
| 287 | this.height = height; |
| 288 | } |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 289 | |
| 290 | static goldenRectangle() { |
| 291 | var PHI = (1 + Math.sqrt(5)) / 2; |
| 292 | return new Rectangle(0, 0, PHI, 1); |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 293 | } |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 294 | } |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 295 | ``` |
| 296 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 297 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 298 | |
| 299 | **Discussion Notes / Link to Thread:** |
| 300 | |
| 301 | --- |
| 302 | |
| 303 | ## Block Scope Functions |
| 304 | |
| 305 | **Usage Example:** |
| 306 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 307 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 308 | { |
| 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 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 323 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-functiondeclarationinstantiation) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 324 | |
| 325 | **Discussion Notes / Link to Thread:** |
| 326 | |
| 327 | --- |
| 328 | |
| 329 | ## Default Function Parameters |
| 330 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 331 | Initialize parameters with default values if no value or `undefined` is passed. |
| 332 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 333 | **Usage Example:** |
| 334 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 335 | ```js |
| 336 | /** |
| 337 | * @param {!Element} element An element to hide. |
| 338 | * @param {boolean=} animate Whether to animatedly hide |element|. |
| 339 | */ |
| 340 | function hide(element, animate=true) { |
| 341 | function setHidden() { element.hidden = true; } |
| 342 | |
| 343 | if (animate) |
| 344 | element.animate({...}).then(setHidden); |
| 345 | else |
| 346 | setHidden(); |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 347 | } |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 348 | |
| 349 | hide(document.body); // Animated, animate=true by default. |
| 350 | hide(document.body, false); // Not animated. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 351 | ``` |
| 352 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 353 | **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) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 355 | |
| 356 | **Discussion Notes / Link to Thread:** |
| 357 | |
| 358 | --- |
| 359 | |
| 360 | ## Rest Parameters |
| 361 | |
| 362 | Aggregation of function arguments into one Array variable. |
| 363 | |
| 364 | **Usage Example:** |
| 365 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 366 | ```js |
| 367 | function usesRestParams(a, b, ...theRest) { |
| 368 | console.log(a); // 'a' |
| 369 | console.log(b); // 'b' |
| 370 | console.log(theRest); // [1, 2, 3] |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 371 | } |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 372 | |
| 373 | usesRestParams('a', 'b', 1, 2, 3); |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 374 | ``` |
| 375 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 376 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 377 | |
| 378 | **Discussion Notes / Link to Thread:** |
| 379 | |
| 380 | --- |
| 381 | |
| 382 | ## Spread Operators |
| 383 | |
| 384 | Spreading the elements from an iterable collection into individual literals as |
| 385 | function parameters. |
| 386 | |
| 387 | **Usage Example:** |
| 388 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 389 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 390 | // Spreading an Array |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 391 | var params = ['hello', true, 7]; |
| 392 | var other = [1, 2, ...params]; // [1, 2, 'hello', true, 7] |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 393 | |
| 394 | // Spreading a String |
| 395 | var str = 'foo'; |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 396 | var chars = [...str]; // ['f', 'o', 'o'] |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 397 | ``` |
| 398 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 399 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-argument-lists-runtime-semantics-argumentlistevaluation) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 400 | |
| 401 | **Discussion Notes / Link to Thread:** |
| 402 | |
| 403 | --- |
| 404 | |
| 405 | ## Object Literal Extensions |
| 406 | |
| 407 | Convenient new ways for object property definition. |
| 408 | |
| 409 | **Usage Example:** |
| 410 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 411 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 412 | // Computed property name |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 413 | var prop = 'foo'; |
| 414 | var o = { |
| 415 | [prop]: 'hey', |
| 416 | ['b' + 'ar']: 'there', |
| 417 | }; |
| 418 | console.log(o); // {foo: 'hey', bar: 'there'} |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 419 | |
| 420 | // Shorthand property |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 421 | var foo = 1; |
| 422 | var bar = 2; |
| 423 | var o = {foo, bar}; |
| 424 | console.log(o); // {foo: 1, bar: 2} |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 425 | |
| 426 | // Method property |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 427 | var clearSky = { |
| 428 | // Basically the same as clouds: function() { return 0; }. |
| 429 | clouds() { return 0; }, |
| 430 | color() { return 'blue'; }, |
| 431 | }; |
| 432 | console.log(clearSky.color()); // 'blue' |
| 433 | console.log(clearSky.clouds()); // 0 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 434 | ``` |
| 435 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 436 | **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) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 438 | |
| 439 | **Discussion Notes / Link to Thread:** |
| 440 | |
| 441 | --- |
| 442 | |
| 443 | ## Template Literals |
| 444 | |
| 445 | Expression interpolation for Strings, with the ability to access raw template |
| 446 | pieces. |
| 447 | |
| 448 | **Usage Example:** |
| 449 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 450 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 451 | // Simple example |
| 452 | var greeting = 'hello'; |
| 453 | var myName = {first: 'Foo', last: 'Bar'}; |
| 454 | var message = `${greeting}, |
| 455 | my name is ${myName.first + myName.last}`; |
| 456 | // message == 'hello,\nmy name is FooBar' |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 457 | ``` |
| 458 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 459 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-template-literals) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 460 | |
| 461 | **Discussion Notes / Link to Thread:** |
| 462 | |
| 463 | --- |
| 464 | |
| 465 | ## Binary & Octal Literals |
| 466 | |
| 467 | **Usage Example:** |
| 468 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 469 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 470 | 0b111110111 === 503; |
| 471 | 0o767 === 503; |
| 472 | ``` |
| 473 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 474 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-literals-numeric-literals) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 475 | |
| 476 | **Discussion Notes / Link to Thread:** |
| 477 | |
| 478 | --- |
| 479 | |
| 480 | ## `/u` Unicode Regex Literal |
| 481 | |
| 482 | **Usage Example:** |
| 483 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 484 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 485 | 'ð ®·'.match(/./u)[0].length === 2; |
| 486 | ``` |
| 487 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 488 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-get-regexp.prototype.sticky) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 489 | |
| 490 | **Discussion Notes / Link to Thread:** |
| 491 | |
| 492 | --- |
| 493 | |
| 494 | ## `\u{}` Unicode String |
| 495 | |
| 496 | **Usage Example:** |
| 497 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 498 | ```js |
| 499 | '\u{1d306}' == '\ud834\udf06'; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 500 | ``` |
| 501 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 502 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-literals-string-literals) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 503 | |
| 504 | **Discussion Notes / Link to Thread:** |
| 505 | |
| 506 | --- |
| 507 | |
| 508 | ## `/y` Regex Sticky Matching |
| 509 | |
| 510 | Keep the matching position sticky between matches and this way support |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 511 | efficient parsing of arbitrarily long input strings, even with an arbitrary |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 512 | number of distinct regular expressions. |
| 513 | |
| 514 | **Usage Example:** |
| 515 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 516 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 517 | var re = new RegExp('yy', 'y'); |
| 518 | re.lastIndex = 3; |
| 519 | var result = re.exec('xxxyyxx')[0]; |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 520 | result === 'yy' && re.lastIndex === 5; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 521 | ``` |
| 522 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 523 | **Documentation:** [link](http://es6-features.org/#RegularExpressionStickyMatching) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 524 | |
| 525 | **Discussion Notes / Link to Thread:** |
| 526 | |
| 527 | --- |
| 528 | |
| 529 | ## Destructuring Assignment |
| 530 | |
| 531 | Flexible destructuring of collections or parameters. |
| 532 | |
| 533 | **Usage Example:** |
| 534 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 535 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 536 | // Array |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 537 | var [a, , b] = [1, 2, 3]; // a = 1, b = 3 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 538 | |
| 539 | // Object |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 540 | var {width, height} = document.body.getBoundingClientRect(); |
| 541 | // width = rect.width, height = rect.height |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 542 | |
| 543 | // Parameters |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 544 | function f([name, val]) { |
| 545 | console.log(name, val); // 'bar', 42 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 546 | } |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 547 | f(['bar', 42, 'extra 1', 'extra 2']); // 'extra 1' and 'extra 2' are ignored. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 548 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 549 | function g({name: n, val: v}) { |
| 550 | console.log(n, v); // 'foo', 7 |
| 551 | } |
| 552 | g({name: 'foo', val: 7}); |
| 553 | |
| 554 | function h({name, val}) { |
| 555 | console.log(name, val); // 'bar', 42 |
| 556 | } |
| 557 | h({name: 'bar', val: 42}); |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 558 | |
| 559 | ``` |
| 560 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 561 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-destructuring-assignment) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 562 | |
| 563 | **Discussion Notes / Link to Thread:** |
| 564 | |
| 565 | --- |
| 566 | |
| 567 | ## Modules |
| 568 | |
| 569 | Support for exporting/importing values from/to modules without global |
| 570 | namespace pollution. |
| 571 | |
| 572 | **Usage Example:** |
| 573 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 574 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 575 | // lib/rect.js |
| 576 | export function getArea() {...}; |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 577 | export {width, height, unimportant}; |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 578 | |
| 579 | // app.js |
| 580 | import {getArea, width, height} from 'lib/rect'; |
| 581 | |
| 582 | ``` |
| 583 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 584 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-modules) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 585 | |
| 586 | **Discussion Notes / Link to Thread:** |
| 587 | |
| 588 | --- |
| 589 | |
| 590 | ## Symbol Type |
| 591 | |
| 592 | Unique and immutable data type to be used as an identifier for object |
| 593 | properties. |
| 594 | |
| 595 | **Usage Example:** |
| 596 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 597 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 598 | const foo = Symbol(); |
| 599 | const bar = Symbol(); |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 600 | typeof foo === 'symbol'; // true |
| 601 | typeof bar === 'symbol'; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 602 | let obj = {}; |
| 603 | obj[foo] = 'foo'; |
| 604 | obj[bar] = 'bar'; |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 605 | JSON.stringify(obj); // {} |
| 606 | Object.keys(obj); // [] |
| 607 | Object.getOwnPropertyNames(obj); // [] |
| 608 | Object.getOwnPropertySymbols(obj); // [foo, bar] |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 609 | ``` |
| 610 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 611 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-symbol-constructor) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 612 | |
| 613 | **Discussion Notes / Link to Thread:** |
| 614 | |
| 615 | --- |
| 616 | |
| 617 | ## `for ...of` Loops |
| 618 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 619 | Convenient operator to iterate over all values in an iterable collection. This |
| 620 | differs from `for ...in`, which iterates over all iterable properties. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 621 | |
| 622 | **Usage Example:** |
| 623 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 624 | ```js |
| 625 | // Given an iterable collection fibonacci numbers... |
| 626 | for (var n of fibonacci) { |
| 627 | console.log(n); // 1, 1, 2, 3, ... |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 628 | } |
| 629 | ``` |
| 630 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 631 | **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) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 633 | |
| 634 | **Discussion Notes / Link to Thread:** |
| 635 | |
| 636 | --- |
| 637 | |
| 638 | ## Object Static Methods |
| 639 | |
| 640 | **Usage Example:** |
| 641 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 642 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 643 | // Object.assign |
dbeam | c5454c2f | 2016-12-13 21:43:18 | [diff] [blame] | 644 | var o = Object.assign({a:true}, {b:true}, {c:true}); // {a: true, b: true, c: true} |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 645 | 'a' in o && 'b' in o && 'c' in o; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 646 | |
| 647 | // Object.setPrototypeOf |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 648 | Object.setPrototypeOf({}, Array.prototype) instanceof Array; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 649 | |
| 650 | // Object.is |
dbeam | c5454c2f | 2016-12-13 21:43:18 | [diff] [blame] | 651 | Object.is(null, null) // true |
| 652 | Object.is(NaN, NaN) // true |
| 653 | Object.is(-0, +0) // false, btw: -0 === +0 is true |
| 654 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 655 | // Object.getOwnPropertySymbols |
| 656 | ``` |
| 657 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 658 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-object-constructor) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 659 | |
| 660 | **Discussion Notes / Link to Thread:** |
| 661 | |
| 662 | --- |
| 663 | |
| 664 | ## String Static & Prototype methods |
| 665 | |
| 666 | **Usage Example:** |
| 667 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 668 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 669 | // 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 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 680 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-string-constructor) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 681 | |
| 682 | **Discussion Notes / Link to Thread:** |
| 683 | |
| 684 | --- |
| 685 | |
| 686 | ## Array Static & Prototype Methods |
| 687 | |
| 688 | **Usage Example:** |
| 689 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 690 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 691 | // 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 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 703 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-array-constructor) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 704 | |
| 705 | **Discussion Notes / Link to Thread:** |
| 706 | |
| 707 | --- |
| 708 | |
| 709 | ## Number Properties |
| 710 | |
| 711 | **Usage Example:** |
| 712 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 713 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 714 | // 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 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 723 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-isfinite-number) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 724 | |
| 725 | **Discussion Notes / Link to Thread:** |
| 726 | |
| 727 | --- |
| 728 | |
| 729 | ## Iterators |
| 730 | |
| 731 | **Usage Example:** |
| 732 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 733 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 734 | let fibonacci = { |
| 735 | [Symbol.iterator]() { |
| 736 | let pre = 0, cur = 1; |
| 737 | return { |
| 738 | next () { |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 739 | [pre, cur] = [cur, pre + cur]; |
| 740 | return {done: false, value: cur}; |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 741 | } |
| 742 | }; |
| 743 | } |
| 744 | }; |
| 745 | ``` |
| 746 | |
| 747 | **Documentation:** [link]() |
| 748 | |
| 749 | **Discussion Notes / Link to Thread:** |
| 750 | |
| 751 | --- |
| 752 | |
| 753 | ## Generators |
| 754 | |
| 755 | Special iterators with specified pausing points. |
| 756 | |
| 757 | **Usage Example:** |
| 758 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 759 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 760 | function* range(start, end, step) { |
| 761 | while (start < end) { |
| 762 | yield start; |
| 763 | start += step; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | for (let i of range(0, 10, 2)) { |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 768 | console.log(i); // 0, 2, 4, 6, 8 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | ``` |
| 772 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 773 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-generator-function-definitions) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 774 | |
| 775 | **Discussion Notes / Link to Thread:** |
| 776 | |
| 777 | --- |
| 778 | |
| 779 | ## `Map` |
| 780 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 781 | A simple key/value map in which any value (both objects and primitive values) |
| 782 | may be used as either a key or a value. |
| 783 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 784 | **Usage Example:** |
| 785 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 786 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 787 | var map = new Map(); |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 788 | map.size === 0; // true |
| 789 | map.get('foo'); // undefined |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 790 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 791 | var key = {}; |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 792 | map.set(key, 123); |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 793 | map.size === 1; // true |
| 794 | map.has(key); // true |
| 795 | map.get(key); // 123 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 796 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 797 | map.delete(key); |
| 798 | map.has(key); // false |
| 799 | map.size === 0; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 800 | ``` |
| 801 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 802 | **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) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 804 | |
| 805 | **Discussion Notes / Link to Thread:** |
| 806 | |
| 807 | --- |
| 808 | |
| 809 | ## `Set` |
| 810 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 811 | An object that lets you store unique values of any type, whether primitive |
| 812 | values or object references. |
| 813 | |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 814 | **Usage Example:** |
| 815 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 816 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 817 | var set = new Set(); |
| 818 | |
| 819 | set.add(123); |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 820 | set.size(); // 1 |
| 821 | set.has(123); // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 822 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 823 | set.add(123); |
| 824 | set.size(); // 1 |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 825 | ``` |
| 826 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 827 | **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) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 829 | |
| 830 | **Discussion Notes / Link to Thread:** |
| 831 | |
| 832 | --- |
| 833 | |
| 834 | ## `WeakMap` |
| 835 | |
| 836 | WeakMap does not prevent garbage collection if nothing else refers to an object |
| 837 | within the collection. |
| 838 | |
| 839 | **Usage Example:** |
| 840 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 841 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 842 | var key = {}; |
| 843 | var weakmap = new WeakMap(); |
| 844 | |
| 845 | weakmap.set(key, 123); |
| 846 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 847 | weakmap.has(key) && weakmap.get(key) === 123; // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 848 | ``` |
| 849 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 850 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-weakmap-objects) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 851 | |
| 852 | **Discussion Notes / Link to Thread:** |
| 853 | |
| 854 | --- |
| 855 | |
| 856 | ## `WeakSet` |
| 857 | |
| 858 | WeakSet does not prevent garbage collection if nothing else refers to an object |
| 859 | within the collection. |
| 860 | |
| 861 | **Usage Example:** |
| 862 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 863 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 864 | var obj1 = {}; |
| 865 | var weakset = new WeakSet(); |
| 866 | |
| 867 | weakset.add(obj1); |
| 868 | weakset.add(obj1); |
| 869 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 870 | weakset.has(obj1); // true |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 871 | ``` |
| 872 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 873 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-weakset-objects) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 874 | |
| 875 | **Discussion Notes / Link to Thread:** |
| 876 | |
| 877 | --- |
| 878 | |
| 879 | ## Typed Arrays |
| 880 | |
| 881 | A lot of new typed Arrays... |
| 882 | |
| 883 | **Usage Example:** |
| 884 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 885 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 886 | new Int8Array(); |
| 887 | new UInt8Array(); |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 888 | new UInt8ClampedArray(); |
| 889 | // ... You get the idea. Click on the Documentation link below to see all. |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 890 | ``` |
| 891 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 892 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 893 | |
| 894 | **Discussion Notes / Link to Thread:** |
| 895 | |
| 896 | --- |
| 897 | |
| 898 | ## `Proxy` |
| 899 | |
| 900 | Hooking into runtime-level object meta-operations. |
| 901 | |
| 902 | **Usage Example:** |
| 903 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 904 | ```js |
| 905 | var 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 | }, |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 917 | }); |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 918 | |
| 919 | keyTracker.key1; // '1 keys created!' |
| 920 | keyTracker.key1; // 'key already exists' |
| 921 | keyTracker.key2; // '2 keys created!' |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 922 | ``` |
| 923 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 924 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 925 | |
| 926 | **Discussion Notes / Link to Thread:** |
| 927 | |
| 928 | --- |
| 929 | |
| 930 | ## `Reflection` |
| 931 | |
| 932 | Make calls corresponding to the object meta-operations. |
| 933 | |
| 934 | **Usage Example:** |
| 935 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 936 | ```js |
| 937 | let obj = {a: 1}; |
| 938 | Object.defineProperty(obj, 'b', {value: 2}); |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 939 | obj[Symbol('c')] = 3; |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 940 | Reflect.ownKeys(obj); // ['a', 'b', Symbol(c)] |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 941 | ``` |
| 942 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 943 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-reflection) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 944 | |
| 945 | **Discussion Notes / Link to Thread:** |
| 946 | |
| 947 | --- |
| 948 | |
| 949 | ## Math Methods |
| 950 | |
| 951 | A lot of new Math methods. |
| 952 | |
| 953 | **Usage Example:** |
| 954 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 955 | ```js |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 956 | // See Doc |
| 957 | ``` |
| 958 | |
dbeam | 814fb45 | 2016-12-06 22:55:15 | [diff] [blame] | 959 | **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-math) |
scottchen | 84ef86ca | 2016-12-06 01:14:53 | [diff] [blame] | 960 | |
| 961 | **Discussion Notes / Link to Thread:** |
| 962 | |
| 963 | --- |