Skip to content

Commit 26c2073

Browse files
authored
Merge pull request #96 from hemanth/code-samples
Code samples
2 parents 5be87ba + 8fed776 commit 26c2073

File tree

1 file changed

+96
-71
lines changed

1 file changed

+96
-71
lines changed

Diff for: _data/stage3.yml

+96-71
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
- title: Function.prototype.toString revision
2-
description: for functions defined using ECMAScript code, toString must return source text slice from beginning of first token to end of last token matched by the appropriate grammar production
3-
authors:
4-
- Michael Ficarra
5-
champions:
6-
- Michael Ficarra
7-
tests:
8-
- https://github.com/tc39/test262/issues/1163
9-
specification: https://tc39.github.io/Function-prototype-toString-revision/
10-
resources:
11-
- https://github.com/tc39/Function-prototype-toString-revision
12-
131
- title: globalThis
142
description: ECMAScript Proposal, specs, and reference implementation for globalThis
153
authors:
@@ -67,6 +55,14 @@
6755
- Daniel Ehrenberg
6856
tests:
6957
- https://github.com/tc39/test262/issues/1056
58+
example: >
59+
const theBiggestInt = 9007199254740991n;
60+
61+
const alsoHuge = BigInt(9007199254740991);
62+
// ↪ 9007199254740991n
63+
64+
const hugeButString = BigInt('9007199254740991');
65+
// ↪ 9007199254740991n
7066
resources:
7167
- https://github.com/tc39/proposal-bigint
7268

@@ -91,19 +87,34 @@
9187
- Kevin Gibbons
9288
tests:
9389
- https://github.com/tc39/test262/issues/1343
94-
resources:
95-
- https://github.com/tc39/proposal-private-methods
90+
example: >
91+
class Counter extends HTMLElement {
92+
#xValue = 0;
9693
97-
- title: Array.prototype.{flat,flatMap}
98-
description: Proposal for flatten and flatMap on arrays
99-
authors:
100-
- Brian Terlson
101-
- Michael Ficarra
102-
champions:
103-
- Brian Terlson
104-
- Michael Ficarra
94+
get #x() { return #xValue; }
95+
set #x(value) {
96+
this.#xValue = value;
97+
window.requestAnimationFrame(this.#render.bind(this));
98+
}
99+
100+
#clicked() {
101+
this.#x++;
102+
}
103+
104+
constructor() {
105+
super();
106+
this.onclick = this.#clicked.bind(this);
107+
}
108+
109+
connectedCallback() { this.#render(); }
110+
111+
#render() {
112+
this.textContent = this.#x.toString();
113+
}
114+
}
115+
window.customElements.define('num-counter', Counter);
105116
resources:
106-
- https://github.com/tc39/proposal-flatMap
117+
- https://github.com/tc39/proposal-private-methods
107118

108119
- title: Class Public Instance Fields & Private Instance Fields
109120
description: This proposes a combined vision for public fields and private fields, drawing on the earlier Orthogonal Classes and Class Evaluation Order proposals.
@@ -118,8 +129,17 @@
118129
tests:
119130
- https://github.com/tc39/test262/issues/1161
120131
specification: https://tc39.github.io/proposal-class-fields/
132+
example: >
133+
class Foo {
134+
instancePropertyBar = 0;
135+
static staticPropertyBar = 0;
136+
#privatePropertyBar = 0;
137+
static #privatePropertyBar = 0;
138+
139+
set foo(value) { console.log(value); }
140+
}
121141
resources:
122-
- https://github.com/tc39/proposal-numeric-separator
142+
- https://github.com/tc39/proposal-class-fields
123143

124144
- title: Static class fields and private static methods
125145
description: This proposal adds Static public fields, Static private methods and Static private fields
@@ -134,17 +154,36 @@
134154
specification: https://tc39.github.io/proposal-static-class-features/
135155
resources:
136156
- https://tc39.github.io/proposal-static-class-features/
157+
example: >
158+
class ColorFinder {
159+
static #red = "#ff0000";
137160
138-
- title: String.prototype.{trimStart,trimEnd}
139-
description: A proposal to extend ECMA-262 syntax into a superset of JSON.
140-
authors:
141-
- Sebastian Markbåge
142-
champions:
143-
- Sebastian Markbåge
144-
tests:
145-
- https://github.com/tc39/test262/pull/1246
146-
resources:
147-
- https://tc39.github.io/proposal-string-left-right-trim/
161+
static #blue = "#00ff00";
162+
163+
static #green = "#0000ff";
164+
165+
// ^ static class fields
166+
167+
static white = "white";
168+
169+
// ^ static public field.
170+
171+
static colorName(name) {
172+
switch (name) {
173+
case "red": return ColorFinder.#red;
174+
case "blue": return ColorFinder.#blue;
175+
case "green": return ColorFinder.#green;
176+
default: throw new RangeError("unknown color");
177+
}
178+
}
179+
180+
// Static method ^
181+
182+
static #setColor(name) {
183+
184+
}
185+
// ^ Static private method
186+
}
148187
149188
- title: String.prototype.matchAll
150189
description: If given a string, and either a sticky or a global regular expression which has multiple capturing groups, we often want to iterate through all of the matches.
@@ -155,42 +194,28 @@
155194
tests:
156195
- https://github.com/tc39/test262/pull/1500
157196
- https://github.com/tc39/test262/pull/1587
197+
example: >
198+
var str = 'Hello world!!!';
199+
200+
var regexp = /(\w+)\W*/g;
201+
202+
console.log(str.matchAll(regexp));
203+
204+
/*
205+
[
206+
{
207+
0: "Hello ",
208+
1: "Hello"
209+
index: 0,
210+
input: "Hello world!!!"
211+
},
212+
{
213+
0: "world!!!",
214+
1: "world"
215+
index: 6,
216+
input: "Hello world!!!"
217+
}
218+
]
219+
*/
158220
resources:
159221
- https://tc39.github.io/proposal-string-matchall/
160-
161-
- title: Symbol.prototype.description
162-
description: Expose the [[Description]] internal slot of a symbol directly instead of just indirectly through Symbol.prototype.toString.
163-
authors:
164-
- Michael Ficarra
165-
champions:
166-
- Michael Ficarra
167-
tests:
168-
- https://github.com/tc39/test262/pull/1590
169-
resources:
170-
- https://tc39.github.io/proposal-Symbol-description/
171-
172-
- title: Object.fromEntries
173-
description: A proposal for a new static method Object.fromEntries in ECMAScript for transforming a list of key-value pairs into an object.
174-
authors:
175-
- Darien Maillet Valentine
176-
champions:
177-
- Jordan Harband
178-
- Kevin Gibbons
179-
tests:
180-
- https://github.com/tc39/test262/pull/1677
181-
- https://github.com/tc39/test262/pull/1676
182-
resources:
183-
- https://tc39.github.io/proposal-object-from-entries/
184-
185-
- title: Well-formed JSON.stringify
186-
description: A proposal to prevent JSON.stringify from returning ill-formed Unicode strings.
187-
authors:
188-
- Richard Gibson
189-
champions:
190-
- Mathias Bynens
191-
tests:
192-
- https://github.com/tc39/test262/pull/1787
193-
specification: https://tc39.github.io/proposal-well-formed-stringify/
194-
resources:
195-
- https://tc39.github.io/proposal-well-formed-stringify/
196-

0 commit comments

Comments
 (0)