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

Side by Side Diff: docs/es6-chromium.md

Issue 2509183002: Initial pass creating the ES6 feature doc (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!-- ---
2
3 ##
4
5 **Usage Example:**
6
7 ``` js
8
9 ```
10
11 **Documentation:** [link]()
12
13 **Discussion Notes / Link to Thread:**
14 -->
15
16 <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
Dan Beam 2016/11/22 02:37:11 why are we using jquery?
scottchen1 2016/11/22 21:26:58 I had it to save me some time to implement a fixed
17 <script>
18 $(function() {
19 //to show fixed section title for better readability
20 $(window).on('scroll', function(){
21 var closest = null;
22 $('h1').each(function(index, h1){
23 var newTop = h1.getBoundingClientRect().top;
24 if(newTop > 0) {
25 return;
26 } else {
27 if(!closest) {
28 closest = h1;
29 } else {
30 curTop = closest.getBoundingClientRect().top;
31 closest = newTop > curTop ? h1 : closest;
32 }
33 }
34 });
35
36 if(closest) {
37 $('#floating-header').html(closest.textContent).show();
38 } else {
39 $('#floating-header').html('').hide();
40 }
41 });
42 });
43 </script>
44
45 <style type="text/css">
46 .doc {
47 font-size: 16px;
48 }
49
50 .doc h2 > code {
51 font-size: 20px;
52 font-weight: bold;
53 }
54
55 #floating-header {
56 position: fixed;
57 background-color: #eaeaea;
58 border-bottom: silver 1px solid;
59 top: 0;
60 left: 0;
61 right: 0;
62 font: 24px bold;
63 font-family: sans-serif;
64 max-width: 1024px;
65 margin: auto;
66 padding: 10px 20px;
67 display: none;
68 }
69 </style>
70
71 <div id='floating-header'></div>
72
73 [TOC]
74
75 # ES6 Support In Chromium
76
77 This is a list of new/updated features in ES6 specs that is being considered to be supported for Chromium development.
78
79 >**TBD:** Do we want to differenciate allow/ban status between subprojects? If s o, how to denote?
80
81 >**TBD:** Cross platform-build support?
82
83 You can propose changing the status of a feature by sending an email to chromium -dev@chromium.org. Include a short blurb on what the feature is and why you thin k it should or should not be allowed, along with links to any relevant previous discussion. If the list arrives at some consensus, send a codereview to change t his file accordingly, linking to your discussion thread.
84
85 >Some descriptions and Usage examples are from [https://kangax.github.io/compat- table/es6/](https://kangax.github.io/compat-table/es6/) and [http://es6-features .org/](http://es6-features.org/)
86
87 # Allowed Features
88
89 The following features are allowed in Chromium development.
90
91 # Banned Features
92
93 The following features are banned for Chromium development.
94
95 # Features To Be Discussed
96
97 The following features are currently disallowed. See the top of this page on how to propose moving a feature from this list into the allowed or banned sections.
98
99 ---
100
101 ## `let` (Block-Scoped Variables)
102
103 Declare variable that exists within the block scope. `let` can generally be used to replace `var` but `let` in global scope, unlike `var`, does not introduce a property on the global object.
104
105 **Usage Example:**
106
107 ``` js
108 // This will make all buttons output "3"
109 for(let i = 0; i < 3; i++) {
dpapad 2016/11/21 22:59:55 s/let/var?
scottchen1 2016/11/22 21:26:58 Done. Copy paste error.
110 buttons[i].onclick = function() {
111 console.log(i);
112 };
113 }
114
115 // This will make buttons output corresponding "i" values
116 for(let i = 0; i < 3; i++) {
117 buttons[i].onclick = function() {
118 console.log(i);
119 };
120 }
dpapad 2016/11/21 22:59:55 I think there is more to the "let" vs "var" distin
scottchen1 2016/11/22 21:26:58 Done.
121 ```
122
123 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le t-and-const-declarations)
124
125 **Discussion Notes / Link to Thread:**
126
127 ---
128
129 ## `const` (Block-Scoped Constants)
130
131 Constants (also known as "immutable variables") are variables which cannot be re -assigned new content. Note that if the value is an object, the object itself is still mutable.
132
133 `const` has traditionally been supported as a "function scoped" declaration like `var` (except in Internet Explorer), however in VMs supporting ES6 `const` is n ow a block scope declaration.
134
135 **Usage Example:**
136
137 ``` js
138 const gravity = 9.81;
dpapad 2016/11/21 22:59:55 Add an example showing the error shown when trying
scottchen1 2016/11/22 21:26:57 Done.
139 return gravity === 9.81;
140 ```
141
142 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-le t-and-const-declarations)
143
144 **Discussion Notes / Link to Thread:**
145
146 ---
147
148 ## `=>` (Arrow Functions)
149
150 Shorthand for creating a function, with automatic binding of `this` to code cont ext, and implicit return when used without a body block.
151
152 **Usage Example:**
153
154 ``` js
155 () => 1 // returns 1
156 () => [] // returns []
157 () => {} // returns undefined
158 () => ({}) // returns {}
159 () => {1} // returns undefined
160 () => {return 1;} // returns 1
161
162 ele.onclick = () => this.clickHandler()
163 ```
164
165 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ar row-function-definitions)
166
167 **Discussion Notes / Link to Thread:**
168
169 ---
170
171 ## Classes
172
173 OOP-style and boilerplate-free class syntax, including inheritance, super(), sta tic members, and getters and setters.
174
175 **Usage Example:**
176
177 ``` js
178 class Rectangle extends Shape {
179 constructor (id, x, y, width, height) {
180 super(id, x, y);
181 this.width = width;
182 this.height = height;
183 }
184 static defaultRectangle () {
185 return new Rectangle("default", 0, 0, 100, 100)
dpapad 2016/11/21 22:59:55 Indent is off by 2. Should double quotes be switch
scottchen1 2016/11/22 21:26:57 Done. Yeah I think it's a good idea to change it t
186 }
187 move (x, y) {
188 this.x = x;
189 this.y = y;
190 }
191 };
192 ```
193
194 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-cl ass-definitions)
195
196 **Discussion Notes / Link to Thread:**
197
198 ---
199
200 ## `Promise`
dpapad 2016/11/21 22:59:55 We are already using this extensively, so perhaps
scottchen1 2016/11/22 21:26:57 Done.
201
202 Built-in representation of a value that might be determined asynchronously, reli eving developers from "callback hell".
203
204 **Usage Example:**
205
206 ``` js
207 function promiseA() { return new Promise((resolve, reject) => setTimeout(resolve , 100)); }
208 function promiseB() { return new Promise((resolve, reject) => setTimeout(resolve , 200)); }
209 function promiseC() { return new Promise((resolve, reject) => setTimeout(resolve , 300)); }
210
211 Promise.all([promiseA(), promiseB(), promiseC()]).then(([a, b, c]) => {
212 someFunction(a, b, c);
213 });
214 ```
215
216 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr omise-objects)
217
218 **Discussion Notes / Link to Thread:**
219
220 ---
221
222 ## Block Scope Functions
223
224 **Usage Example:**
225
226 ``` js
227 {
228 function foo () { return 1; }
229 //foo() === 1
230 {
231 function foo () { return 2; }
232 //foo() === 2
233 }
234 //foo() === 1
235 }
236 ```
237
238 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fu nctiondeclarationinstantiation)
239
240 **Discussion Notes / Link to Thread:**
241
242 ---
243
244 ## Default Function Parameters
245
246 **Usage Example:**
247
248 ``` js
249 function f (x, y = 7, z = 42) {
250 return x + y + z;
251 }
252 //f(1) === 50;
253 ```
254
255 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fu nctiondeclarationinstantiation)
256
257 **Discussion Notes / Link to Thread:**
258
259 ---
260
261 ## Rest Parameters
262
263 Aggregation of function arguments into one Array variable.
264
265 **Usage Example:**
266
267 ``` js
268 function f (x, y, ...a) {
269 // for f(1, 2, 3, 4, 5)...
270 // x = 1, y = 2
271 // a = [3, 4, 5]
272 }
273 ```
274
275 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fu nction-definitions)
276
277 **Discussion Notes / Link to Thread:**
278
279 ---
280
281 ## Spread Operators
282
283 Spreading the elements from an iterable collection into individual literals as f unction parameters.
284
285 **Usage Example:**
286
287 ``` js
288 // Spreading an Array
289 var params = [ "hello", true, 7 ];
290 var other = [ 1, 2, ...params ]; // [ 1, 2, "hello", true, 7 ]
291 f(1, 2, ...params) === 9;
292
293 // Spreading a String
294 var str = "foo";
295 var chars = [ ...str ]; // [ "f", "o", "o" ]
296 ```
297
298 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ar gument-lists-runtime-semantics-argumentlistevaluation)
299
300 **Discussion Notes / Link to Thread:**
301
302 ---
303
304 ## Object Literal Extensions
305
306 Convenient new ways for object property definition.
307
308 **Usage Example:**
309
310 ``` js
311 //computed property name
312 var x = "key";
313 var obj = {[x]: 1}
314
315 //shorthand property
316 var obj = {x, y} //equivalent to {x:x, y:y}
317
318 //method property
319 var obj = {
320 foo() {...},
321 bar() {...}
322 }
323 ```
324
325 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ob ject-initialiser)
326
327 **Discussion Notes / Link to Thread:**
328
329 ---
330
331 ## Template Literals
332
333 Expression interpolation for Strings, with the ability to access raw template pi eces.
334
335 **Usage Example:**
336
337 ``` js
338 // Simple example
339 var greeting = "hello";
340 var name = {first: "Foo", last: "Bar"};
341 var message = `${ greeting },
dpapad 2016/11/21 22:59:55 Can we remove the extra spaces around the brackets
scottchen1 2016/11/22 21:26:57 Done.
342 Your name is ${ name.first + namelast }`;
343
344 // Custom interpolation
345 function foo (strings, ...values) {
346 strings[0] === "bar";
347 strings[1] === "baz";
348 values[0] === 42;
349
350 //...
351 return customResult;
352 }
353
354 foo`bar${ 42 }baz`
355 ```
356
357 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-te mplate-literals)
358
359 **Discussion Notes / Link to Thread:**
360
361 ---
362
363 ## Binary & Octal Literals
364
365 **Usage Example:**
366
367 ``` js
368 0b111110111 === 503;
369 0o767 === 503;
370 ```
371
372 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-li terals-numeric-literals)
373
374 **Discussion Notes / Link to Thread:**
375
376 ---
377
378 ## `/u` Unicode Regex Literal
379
380 **Usage Example:**
381
382 ``` js
383 "ð ®·".match(/./u)[0].length === 2;
384 ```
385
386 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ge t-regexp.prototype.sticky)
387
388 **Discussion Notes / Link to Thread:**
389
390 ---
391
392 ## `\u{}` Unicode String
393
394 **Usage Example:**
395
396 ``` js
397 return '\u{1d306}' == '\ud834\udf06';
398 ```
399
400 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-li terals-string-literals)
401
402 **Discussion Notes / Link to Thread:**
403
404 ---
405
406 ## `/y` Regex Sticky Matching
407
408 Keep the matching position sticky between matches and this way support efficient parsing of arbitrary long input strings, even with an arbitrary number of disti nct regular expressions.
409
410 **Usage Example:**
411
412 ``` js
413 var re = new RegExp('yy', 'y');
414 re.lastIndex = 3;
415 var result = re.exec('xxxyyxx')[0];
416 return result === 'yy' && re.lastIndex === 5;
417 ```
418
419 **Documentation:** [link](http://es6-features.org/#RegularExpressionStickyMatchi ng)
420
421 **Discussion Notes / Link to Thread:**
422
423 ---
424
425 ## Destructuring Assignment
426
427 Flexible destructuring of collections or parameters.
428
429 **Usage Example:**
430
431 ``` js
432 //array
433 var list = [ 1, 2, 3 ];
434 var [ a, , b ] = list;
435 //a = 1, b = 3
436
437 //object
438 var {width, height, area: a} = rect;
439 //width = rect.width, height = rect.height, a = rect.area
440
441 //parameters
442 function f ([ name, val ]) {
443 console.log(name, val);
444 }
445 function g ({ name: n, val: v }) {
446 console.log(n, v);
447 }
448 function h ({ name, val }) {
449 console.log(name, val);
450 }
451 f([ "bar", 42 ]);
452 g({ name: "foo", val: 7 });
453 h({ name: "bar", val: 42 });
454
455 ```
456
457 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-de structuring-assignment)
458
459 **Discussion Notes / Link to Thread:**
460
461 ---
462
463 ## Modules
464
465 Support for exporting/importing values from/to modules without global namespace pollution.
466
467 **Usage Example:**
468
469 ``` js
470 //lib/rect.js
471 export function getArea() {...};
472 export { width, height, unimportant };
473
474 //app.js
475 import {getArea, width, height} from "lib/rect";
476
477 ```
478
479 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-mo dules)
480
481 **Discussion Notes / Link to Thread:**
482
483 ---
484
485 ## Symbol Type
486
487 Unique and immutable data type to be used as an identifier for object properties .
488
489 **Usage Example:**
490
491 ``` js
492 const foo = Symbol();
493 const bar = Symbol();
494 typeof foo === "symbol";
495 typeof bar === "symbol";
496 let obj = {};
497 obj[foo] = "foo";
498 obj[bar] = "bar";
499 JSON.stringify(obj); // {}
500 Object.keys(obj); // []
501 Object.getOwnPropertyNames(obj); // []
502 Object.getOwnPropertySymbols(obj); // [ foo, bar ]
503 ```
504
505 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-sy mbol-constructor)
506
507 **Discussion Notes / Link to Thread:**
508
509 ---
510
511 ## `for ...of` Loops
512
513 Convenient operator to iterate over all values of an iterable object.
514
515 **Usage Example:**
516
517 ``` js
518 for (let n of fibonacci) {
519 console.log(n);
520 }
521 ```
522
523 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-fo r-in-and-for-of-statements)
524
525 **Discussion Notes / Link to Thread:**
526
527 ---
528
529 ## Object Static Methods
530
531 **Usage Example:**
532
533 ``` js
534 //Object.assign
535 var o = Object.assign({a:true}, {b:true}, {c:true});
536 return "a" in o && "b" in o && "c" in o;
537
538 //Object.setPrototypeOf
539 return Object.setPrototypeOf({}, Array.prototype) instanceof Array; //true
540
541 //Object.is
542 //Object.getOwnPropertySymbols
543 ```
544
545 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr operties-of-the-object-constructor)
546
547 **Discussion Notes / Link to Thread:**
548
549 ---
550
551 ## String Static & Prototype methods
552
553 **Usage Example:**
554
555 ``` js
556 //String.raw
557 //String.fromCodePoint
558
559 //String.prototype.codePointAt
560 //String.prototype.normalize
561 //String.prototype.repeat
562 //String.prototype.startsWith
563 //String.prototype.endsWith
564 //String.prototype.includes
565 ```
566
567 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr operties-of-the-string-constructor)
568
569 **Discussion Notes / Link to Thread:**
570
571 ---
572
573 ## Array Static & Prototype Methods
574
575 **Usage Example:**
576
577 ``` js
578 //Array.from
579 //Array.of
580
581 //Array.prototype.copyWithin
582 //Array.prototype.find
583 //Array.prototype.findIndex
584 //Array.prototype.fill
585 //Array.prototype.keys
586 //Array.prototype.values
587 //Array.prototype.entries
588 ```
589
590 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr operties-of-the-array-constructor)
591
592 **Discussion Notes / Link to Thread:**
593
594 ---
595
596 ## Number Properties
597
598 **Usage Example:**
599
600 ``` js
601 //Number.isFinite
602 //Number.isInteger
603 //Number.isSafeInteger
604 //Number.isNaN
605 //Number.EPSILON
606 //Number.MIN_SAFE_INTEGER
607 //Number.MAX_SAFE_INTEGER
608 ```
609
610 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-is finite-number)
611
612 **Discussion Notes / Link to Thread:**
613
614 ---
615
616 ## Iterators
617
618 **Usage Example:**
619
620 ``` js
621 let fibonacci = {
622 [Symbol.iterator]() {
623 let pre = 0, cur = 1;
624 return {
625 next () {
626 [ pre, cur ] = [ cur, pre + cur ];
627 return { done: false, value: cur };
628 }
629 };
630 }
631 }
632 ```
633
634 **Documentation:** [link]()
635
636 **Discussion Notes / Link to Thread:**
637
638 ---
639
640 ## Generators
641
642 Special iterators with specified pausing points.
643
644 **Usage Example:**
645
646 ``` js
647 function* range (start, end, step) {
648 while (start < end) {
649 yield start;
650 start += step;
651 }
652 }
653
654 for (let i of range(0, 10, 2)) {
655 console.log(i); // 0, 2, 4, 6, 8
656 }
657
658 ```
659
660 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ge nerator-function-definitions)
661
662 **Discussion Notes / Link to Thread:**
663
664 ---
665
666 ## `Map`
667
668 **Usage Example:**
669
670 ``` js
671 var key = {};
672 var map = new Map();
673
674 map.set(key, 123);
675
676 return map.has(key) && map.get(key) === 123;
677 ```
678
679 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma p-objects)
680
681 **Discussion Notes / Link to Thread:**
682
683 ---
684
685 ## `Set`
686
687 **Usage Example:**
688
689 ``` js
690 var obj = {};
691 var set = new Set();
692
693 set.add(123);
694 set.add(123);
695
696 return set.has(123);
697 ```
698
699 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-se t-objects)
700
701 **Discussion Notes / Link to Thread:**
702
703 ---
704
705 ## `WeakMap`
706
707 WeakMap does not prevent garbage collection if nothing else refers to an object within the collection.
708
709 **Usage Example:**
710
711 ``` js
712 var key = {};
713 var weakmap = new WeakMap();
714
715 weakmap.set(key, 123);
716
717 return weakmap.has(key) && weakmap.get(key) === 123;
718 ```
719
720 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-we akmap-objects)
721
722 **Discussion Notes / Link to Thread:**
723
724 ---
725
726 ## `WeakSet`
727
728 WeakSet does not prevent garbage collection if nothing else refers to an object within the collection.
729
730 **Usage Example:**
731
732 ``` js
733 var obj1 = {};
734 var weakset = new WeakSet();
735
736 weakset.add(obj1);
737 weakset.add(obj1);
738
739 return weakset.has(obj1);
740 ```
741
742 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-we akset-objects)
743
744 **Discussion Notes / Link to Thread:**
745
746 ---
747
748 ## Typed Arrays
749
750 A lot of new typed Arrays...
751
752 **Usage Example:**
753
754 ``` js
755 new Int8Array();
756 new UInt8Array();
757 new UInt8ClampedArray()
758 //... You get the idea. Click on the Documentation link below to see all.
759 ```
760
761 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ty pedarray-objects)
762
763 **Discussion Notes / Link to Thread:**
764
765 ---
766
767 ## `Proxy`
768
769 Hooking into runtime-level object meta-operations.
770
771 **Usage Example:**
772
773 ``` js
774 let target = {
775 foo: "Welcome, foo"
776 };
777 let proxy = new Proxy(target, {
778 get (receiver, name) {
779 return name in receiver ? receiver[name] : `Hello, ${name}`;
780 }
781 });
782 proxy.foo === "Welcome, foo";
783 proxy.world === "Hello, world";
784 ```
785
786 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-pr oxy-object-internal-methods-and-internal-slots)
787
788 **Discussion Notes / Link to Thread:**
789
790 ---
791
792 ## `Reflection`
793
794 Make calls corresponding to the object meta-operations.
795
796 **Usage Example:**
797
798 ``` js
799 let obj = { a: 1 };
800 Object.defineProperty(obj, "b", { value: 2 });
801 obj[Symbol("c")] = 3;
802 Reflect.ownKeys(obj); // [ "a", "b", Symbol(c) ]
803 ```
804
805 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-re flection)
806
807 **Discussion Notes / Link to Thread:**
808
809 ---
810
811 ## Math Methods
812
813 A lot of new Math methods.
814
815 **Usage Example:**
816
817 ``` js
818 //See Doc
819 ```
820
821 **Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-ma th)
822
823 **Discussion Notes / Link to Thread:**
824
825 ---
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698