Gion Kunz
Let's create together.
by Gion Kunz
Founder, UI Developer, UX Enthusiast at syncrea GmbH
M31 Andromeda Galaxy, ~2.5 million light-years from Earth and the nearest large galaxy to the Milky Way
ECMAScript 2022
Class field declarations
Private methods and fields
Static public methods and fields
.at() for Indexed Collections
ECMAScript 2020
BigInt
Dynamic Imports
Nullish Coalescing
Optional Chaining
String#matchAll
ECMAScript 2021
String#replaceAll 🥳
WeakRef
const aBigInteger = 98765432123456789n;
const alsoAbigInteger = BigInt('98765432123456789');
console.log(typeof aBigInteger) // bigint
async function getXfromModule() {
const m = await import('./module.js');
return m.x;
}
getXfromModule().then(console.log);
const nullValue = null;
const emptyText = ''; // falsy
const someNumber = 42;
const valA = nullValue ?? 'default for A';
const valB = emptyText ?? 'default for B';
const valC = someNumber ?? 0;
console.log(valA); // 'default for A'
console.log(valB); // ''
console.log(valC); // 42
const adventurer = {
name: 'Alice',
cat: { name: 'Dinah' }
};
const dogName = adventurer.dog?.name;
console.log(dogName);
// expected output: undefined
console.log(adventurer.someNonExistentMethod?.());
// expected output: undefined
const regexp = /foo[a-z]*/g;
const str = 'table football, foosball';
let match;
while ((match = regexp.exec(str)) !== null) {
console.log(`Found ${match[0]} @ ${match.index}`);
}
Before matchAll
const regexp = /foo[a-z]*/g;
const str = 'table football, foosball';
for (const match of str.matchAll(regexp)) {
console.log(`Found ${match[0]} @ ${match.index}`);
}
After matchAll
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
console.log(replaceAll('oOoOoOoOoOo', 'O', '.'));
Before replaceAll
console.log('oOoOoOoOoOo'.replaceAll('O', '.'));
After replaceAll
export function cached(getFresh = () => null) {
let ref;
return () => {
if (!ref || !ref.deref()) {
ref = new WeakRef(getFresh());
}
return ref.deref();
};
}
const cachedData = cached(() => Array(1000).fill(1));
console.log(cachedData());
console.log(cachedData() === cachedData());
export class Fruit {
name;
sweet = true;
color;
}
const banana = new Fruit();
console.log(banana);
// Fruit {sweet: true}
export class Singleton {
static #instance;
constructor() {
return Singleton.#instance ??= this;
}
static instance() {
return new Singleton();
}
}
const s1 = new Singleton();
const s2 = new Singleton();
const s3 = Singleton.instance();
console.log([s1, s2, s3].every(s => s === s1)); // true
// Before
const names = ['Joe', 'Doe', 'Moe'];
console.log(names[names.length - 1]);
// Or
console.log([...names].pop());
// After
console.log(names.at(-1));
By Gion Kunz
Examples of the latest ECMA spec.