OLD | NEW |
---|---|
1 <!-- Feature template markdown: | 1 <!-- Feature template markdown: |
2 ## Header | 2 ## Header |
3 | 3 |
4 **Usage Example:** | 4 **Usage Example:** |
5 | 5 |
6 ```js | 6 ```js |
7 | 7 |
8 ``` | 8 ``` |
9 | 9 |
10 **Documentation:** [link]() | 10 **Documentation:** [link]() |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 previous discussion. If the list arrives at some consensus, send a codereview | 103 previous discussion. If the list arrives at some consensus, send a codereview |
104 to change this file accordingly, linking to your discussion thread. | 104 to change this file accordingly, linking to your discussion thread. |
105 | 105 |
106 > Some descriptions and Usage examples are from [kangax](https://kangax.github.i o/compat-table/es6/) | 106 > Some descriptions and Usage examples are from [kangax](https://kangax.github.i o/compat-table/es6/) |
107 and [http://es6-features.org/](http://es6-features.org/) | 107 and [http://es6-features.org/](http://es6-features.org/) |
108 | 108 |
109 # Allowed Features | 109 # Allowed Features |
110 | 110 |
111 The following features are allowed in Chromium development. | 111 The following features are allowed in Chromium development. |
112 | 112 |
113 ## `=>` (Arrow Functions) | 113 ## => (Arrow Functions) |
114 | 114 |
115 Arrow functions provide a concise syntax to create a function, and fix a number | 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 = | 116 of difficulties with `this` (e.g. eliminating the need to write `const self = |
117 this`). Particularly useful for nested functions or callbacks. | 117 this`). Particularly useful for nested functions or callbacks. |
118 | 118 |
119 Prefer arrow functions over `.bind(this)`. | 119 Prefer arrow functions over `.bind(this)`. |
120 | 120 |
121 Arrow functions have an implicit return when used without a body block. | 121 Arrow functions have an implicit return when used without a body block. |
122 | 122 |
123 **Usage Example:** | 123 **Usage Example:** |
(...skipping 19 matching lines...) Expand all Loading... | |
143 | 143 |
144 **Discussion Notes / Link to Thread:** | 144 **Discussion Notes / Link to Thread:** |
145 | 145 |
146 **Note**: => does not work in iOS9. Don't use it in code that runs on Chrome fo r | 146 **Note**: => does not work in iOS9. Don't use it in code that runs on Chrome fo r |
147 iOS. There's a presubmit that should warn you about this. | 147 iOS. There's a presubmit that should warn you about this. |
148 | 148 |
149 [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chrom ium-dev/iJrC4PVSfoU) | 149 [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chrom ium-dev/iJrC4PVSfoU) |
150 | 150 |
151 --- | 151 --- |
152 | 152 |
153 ## `Promise` | 153 ## Promise |
154 | 154 |
155 The Promise object is used for asynchronous computations. A Promise represents a | 155 The Promise object is used for asynchronous computations. A Promise represents a |
156 value which may be available now, or in the future, or never. | 156 value which may be available now, or in the future, or never. |
157 | 157 |
158 **Usage Example:** | 158 **Usage Example:** |
159 | 159 |
160 ```js | 160 ```js |
161 /** @type {!Promise} */ | 161 /** @type {!Promise} */ |
162 var fullyLoaded = new Promise(function(resolve) { | 162 var fullyLoaded = new Promise(function(resolve) { |
163 function isLoaded() { return document.readyState == 'complete'; } | 163 function isLoaded() { return document.readyState == 'complete'; } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 217 |
218 **Discussion Notes / Link to Thread:** | 218 **Discussion Notes / Link to Thread:** |
219 https://groups.google.com/a/chromium.org/d/msg/chromium-dev/S1h-0m2ohOw/jyaiMGDl CwAJ | 219 https://groups.google.com/a/chromium.org/d/msg/chromium-dev/S1h-0m2ohOw/jyaiMGDl CwAJ |
220 | 220 |
221 **Note**: Not fully supported in iOS9. Don't use it in code that runs on Chrome | 221 **Note**: Not fully supported in iOS9. Don't use it in code that runs on Chrome |
222 for iOS, unless you can verify it works. TODO: Remove this note once support for | 222 for iOS, unless you can verify it works. TODO: Remove this note once support for |
223 iOS9 is dropped. | 223 iOS9 is dropped. |
224 | 224 |
225 --- | 225 --- |
226 | 226 |
227 ## Map | |
228 | |
229 A simple key/value map in which any value (both objects and primitive values) | |
230 may be used as either a key or a value. | |
231 | |
232 **Usage Example:** | |
233 | |
234 ```js | |
235 var map = new Map(); | |
236 map.size === 0; // true | |
237 map.get('foo'); // undefined | |
238 | |
239 var key = {}; | |
michaelpg
2017/06/29 22:10:47
While you're here, I'd suggest changing the exampl
dpapad
2017/06/29 22:16:51
Done.
| |
240 map.set(key, 123); | |
241 map.size === 1; // true | |
242 map.has(key); // true | |
243 map.get(key); // 123 | |
244 | |
245 map.delete(key); | |
246 map.has(key); // false | |
247 map.size === 0; // true | |
248 ``` | |
249 | |
250 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma p-objects) | |
251 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ Objects/Map) | |
252 | |
253 **Discussion Notes:** Feature already extensively used prior to creation of | |
254 this document. | |
255 | |
256 --- | |
257 | |
258 ## Set | |
259 | |
260 An object that lets you store unique values of any type, whether primitive | |
261 values or object references. | |
262 | |
263 **Usage Example:** | |
264 | |
265 ```js | |
266 var set = new Set(); | |
267 | |
268 set.add(123); | |
269 set.size(); // 1 | |
270 set.has(123); // true | |
271 | |
272 set.add(123); | |
273 set.size(); // 1 | |
274 ``` | |
275 | |
276 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-se t-objects) | |
277 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ Objects/Set) | |
278 | |
279 **Discussion Notes:** Feature already extensively used prior to creation of | |
280 this document. | |
281 | |
282 --- | |
283 | |
227 # Banned Features | 284 # Banned Features |
228 | 285 |
229 The following features are banned for Chromium development. | 286 The following features are banned for Chromium development. |
230 | 287 |
231 # Features To Be Discussed | 288 # Features To Be Discussed |
232 | 289 |
233 The following features are currently disallowed. See the top of this page on | 290 The following features are currently disallowed. See the top of this page on |
234 how to propose moving a feature from this list into the allowed or banned | 291 how to propose moving a feature from this list into the allowed or banned |
235 sections. | 292 sections. |
236 | 293 |
237 ## `let` (Block-Scoped Variables) | 294 ## let (Block-Scoped Variables) |
238 | 295 |
239 `let` declares a variable within the scope of a block. This differs from `var`, | 296 `let` declares a variable within the scope of a block. This differs from `var`, |
240 which uses function level scope. | 297 which uses function level scope. |
241 | 298 |
242 **Usage Example:** | 299 **Usage Example:** |
243 | 300 |
244 ```js | 301 ```js |
245 // Scope. | 302 // Scope. |
246 function varTest() { | 303 function varTest() { |
247 var x = 1; | 304 var x = 1; |
(...skipping 22 matching lines...) Expand all Loading... | |
270 let b = 'mundo; // TypeError Identifier 'b' has already been declared. | 327 let b = 'mundo; // TypeError Identifier 'b' has already been declared. |
271 } | 328 } |
272 ``` | 329 ``` |
273 | 330 |
274 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le t-and-const-declarations) | 331 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le t-and-const-declarations) |
275 | 332 |
276 **Discussion Notes / Link to Thread:** | 333 **Discussion Notes / Link to Thread:** |
277 | 334 |
278 --- | 335 --- |
279 | 336 |
280 ## `const` (Block-Scoped Constants) | 337 ## const (Block-Scoped Constants) |
281 | 338 |
282 Constants (also known as "immutable variables") are variables which cannot be | 339 Constants (also known as "immutable variables") are variables which cannot be |
283 re-assigned new content. Note that if the value is an object, the object itself | 340 re-assigned new content. Note that if the value is an object, the object itself |
284 is still mutable. | 341 is still mutable. |
285 | 342 |
286 Also note that in Chrome, `const` is block scoped like `let`. | 343 Also note that in Chrome, `const` is block scoped like `let`. |
287 | 344 |
288 **Usage Example:** | 345 **Usage Example:** |
289 | 346 |
290 ```js | 347 ```js |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 Object.getOwnPropertyNames(obj); // [] | 669 Object.getOwnPropertyNames(obj); // [] |
613 Object.getOwnPropertySymbols(obj); // [foo, bar] | 670 Object.getOwnPropertySymbols(obj); // [foo, bar] |
614 ``` | 671 ``` |
615 | 672 |
616 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-sy mbol-constructor) | 673 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-sy mbol-constructor) |
617 | 674 |
618 **Discussion Notes / Link to Thread:** | 675 **Discussion Notes / Link to Thread:** |
619 | 676 |
620 --- | 677 --- |
621 | 678 |
622 ## `for ...of` Loops | 679 ## for...of Loops |
623 | 680 |
624 Convenient operator to iterate over all values in an iterable collection. This | 681 Convenient operator to iterate over all values in an iterable collection. This |
625 differs from `for ...in`, which iterates over all iterable properties. | 682 differs from `for ...in`, which iterates over all iterable properties. |
626 | 683 |
627 **Usage Example:** | 684 **Usage Example:** |
628 | 685 |
629 ```js | 686 ```js |
630 // Given an iterable collection fibonacci numbers... | 687 // Given an iterable collection fibonacci numbers... |
631 for (var n of fibonacci) { | 688 for (var n of fibonacci) { |
632 console.log(n); // 1, 1, 2, 3, ... | 689 console.log(n); // 1, 1, 2, 3, ... |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 } | 831 } |
775 | 832 |
776 ``` | 833 ``` |
777 | 834 |
778 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ge nerator-function-definitions) | 835 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ge nerator-function-definitions) |
779 | 836 |
780 **Discussion Notes / Link to Thread:** | 837 **Discussion Notes / Link to Thread:** |
781 | 838 |
782 --- | 839 --- |
783 | 840 |
784 ## `Map` | 841 ## WeakMap |
785 | |
786 A simple key/value map in which any value (both objects and primitive values) | |
787 may be used as either a key or a value. | |
788 | |
789 **Usage Example:** | |
790 | |
791 ```js | |
792 var map = new Map(); | |
793 map.size === 0; // true | |
794 map.get('foo'); // undefined | |
795 | |
796 var key = {}; | |
797 map.set(key, 123); | |
798 map.size === 1; // true | |
799 map.has(key); // true | |
800 map.get(key); // 123 | |
801 | |
802 map.delete(key); | |
803 map.has(key); // false | |
804 map.size === 0; // true | |
805 ``` | |
806 | |
807 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma p-objects) | |
808 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ Objects/Map) | |
809 | |
810 **Discussion Notes / Link to Thread:** | |
811 | |
812 --- | |
813 | |
814 ## `Set` | |
815 | |
816 An object that lets you store unique values of any type, whether primitive | |
817 values or object references. | |
818 | |
819 **Usage Example:** | |
820 | |
821 ```js | |
822 var set = new Set(); | |
823 | |
824 set.add(123); | |
825 set.size(); // 1 | |
826 set.has(123); // true | |
827 | |
828 set.add(123); | |
829 set.size(); // 1 | |
830 ``` | |
831 | |
832 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-se t-objects) | |
833 [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ Objects/Set) | |
834 | |
835 **Discussion Notes / Link to Thread:** | |
836 | |
837 --- | |
838 | |
839 ## `WeakMap` | |
840 | 842 |
841 WeakMap does not prevent garbage collection if nothing else refers to an object | 843 WeakMap does not prevent garbage collection if nothing else refers to an object |
842 within the collection. | 844 within the collection. |
843 | 845 |
844 **Usage Example:** | 846 **Usage Example:** |
845 | 847 |
846 ```js | 848 ```js |
847 var key = {}; | 849 var key = {}; |
848 var weakmap = new WeakMap(); | 850 var weakmap = new WeakMap(); |
849 | 851 |
850 weakmap.set(key, 123); | 852 weakmap.set(key, 123); |
851 | 853 |
852 weakmap.has(key) && weakmap.get(key) === 123; // true | 854 weakmap.has(key) && weakmap.get(key) === 123; // true |
853 ``` | 855 ``` |
854 | 856 |
855 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-we akmap-objects) | 857 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-we akmap-objects) |
856 | 858 |
857 **Discussion Notes / Link to Thread:** | 859 **Discussion Notes / Link to Thread:** |
858 | 860 |
859 --- | 861 --- |
860 | 862 |
861 ## `WeakSet` | 863 ## WeakSet |
862 | 864 |
863 WeakSet does not prevent garbage collection if nothing else refers to an object | 865 WeakSet does not prevent garbage collection if nothing else refers to an object |
864 within the collection. | 866 within the collection. |
865 | 867 |
866 **Usage Example:** | 868 **Usage Example:** |
867 | 869 |
868 ```js | 870 ```js |
869 var obj1 = {}; | 871 var obj1 = {}; |
870 var weakset = new WeakSet(); | 872 var weakset = new WeakSet(); |
871 | 873 |
(...skipping 21 matching lines...) Expand all Loading... | |
893 new UInt8ClampedArray(); | 895 new UInt8ClampedArray(); |
894 // ... You get the idea. Click on the Documentation link below to see all. | 896 // ... You get the idea. Click on the Documentation link below to see all. |
895 ``` | 897 ``` |
896 | 898 |
897 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ty pedarray-objects) | 899 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ty pedarray-objects) |
898 | 900 |
899 **Discussion Notes / Link to Thread:** | 901 **Discussion Notes / Link to Thread:** |
900 | 902 |
901 --- | 903 --- |
902 | 904 |
903 ## `Proxy` | 905 ## Proxy |
904 | 906 |
905 Hooking into runtime-level object meta-operations. | 907 Hooking into runtime-level object meta-operations. |
906 | 908 |
907 **Usage Example:** | 909 **Usage Example:** |
908 | 910 |
909 ```js | 911 ```js |
910 var keyTracker = new Proxy({}, { | 912 var keyTracker = new Proxy({}, { |
911 keysCreated: 0, | 913 keysCreated: 0, |
912 | 914 |
913 get (receiver, key) { | 915 get (receiver, key) { |
(...skipping 11 matching lines...) Expand all Loading... | |
925 keyTracker.key1; // 'key already exists' | 927 keyTracker.key1; // 'key already exists' |
926 keyTracker.key2; // '2 keys created!' | 928 keyTracker.key2; // '2 keys created!' |
927 ``` | 929 ``` |
928 | 930 |
929 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr oxy-object-internal-methods-and-internal-slots) | 931 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr oxy-object-internal-methods-and-internal-slots) |
930 | 932 |
931 **Discussion Notes / Link to Thread:** | 933 **Discussion Notes / Link to Thread:** |
932 | 934 |
933 --- | 935 --- |
934 | 936 |
935 ## `Reflection` | 937 ## Reflection |
936 | 938 |
937 Make calls corresponding to the object meta-operations. | 939 Make calls corresponding to the object meta-operations. |
938 | 940 |
939 **Usage Example:** | 941 **Usage Example:** |
940 | 942 |
941 ```js | 943 ```js |
942 let obj = {a: 1}; | 944 let obj = {a: 1}; |
943 Object.defineProperty(obj, 'b', {value: 2}); | 945 Object.defineProperty(obj, 'b', {value: 2}); |
944 obj[Symbol('c')] = 3; | 946 obj[Symbol('c')] = 3; |
945 Reflect.ownKeys(obj); // ['a', 'b', Symbol(c)] | 947 Reflect.ownKeys(obj); // ['a', 'b', Symbol(c)] |
(...skipping 13 matching lines...) Expand all Loading... | |
959 | 961 |
960 ```js | 962 ```js |
961 // See Doc | 963 // See Doc |
962 ``` | 964 ``` |
963 | 965 |
964 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma th) | 966 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma th) |
965 | 967 |
966 **Discussion Notes / Link to Thread:** | 968 **Discussion Notes / Link to Thread:** |
967 | 969 |
968 --- | 970 --- |
OLD | NEW |