From Back-end to Front-end
Киев 2018
ES X
Виталий Ратушный, YouWe
Front-end developer at
ECMAScript vs JavaScript
Who is TC-39?
Why we still need Babel?
Upcoming ES features
What’s difference between
ECMAScript and JavaScript?
https://indesignmedia.net/blog/whats-the-difference-between-javas-and-ecma/
Ecma International
An organization that creates
standards for technologies
ECMA-262
This is a standard
published by Ecma International
ECMA-262 === ECMAScript
JavaScript implements ECMAScript
ECMAScript
how to
CREATE
scripting language
JavaScript
how to
USE
scripting language
Who is TC-39?
Ecma International Technical Committee 39
Who in TC-39?
https://github.com/orgs/tc39/people
TC-39 working process
https://www.sitepen.com/blog/2017/04/06/tc39-open-and-incremental-approach-improves-standards-process/
Stage 0: Strawman Proposal
Stage 1: Proposal
Stage 2: Draft
Stage 4: Finished
Stage 3: Candidate
https://docs.google.com/document/d/1QbEE0BsO4lvl7NFTn5WXWeiEIBfaVUF7Dk0hpPpPDzU/edit
Everyone
Who can create proposal?
https://esdiscuss.org
Just committee every 2 months
Who votes for proposals?
Why do we need
Babel implements TC-39 Stages
Async iterators/generators
Stage 4
https://github.com/tc39/proposal-async-iteration
Domenic Denicola (Google)
Have you ever used streams?
stream.on('readable', () => {
let row;
while (row = parser.read()) {
values += row;
}
});
stream.on('error', err => {…});
stream.on('finish', () => {…});
Callbacks? C’mon 2018
Promises!
for-await-of
async function streamingRead() {
const response = await fetch(‘…');
for await (const chunk of streamAsyncIterator(response.body)) {
console.log(`chunk`, chunk);
}
}
Async Generators
async function* streamAsyncIterator(stream) {
const reader = stream.getReader();
try {
while (true) {
// Read from the stream
const {done, value} = await reader.read();
// Exit if we're done
if (done) return;
// Else yield the chunk
yield value;
}
}
finally {
reader.releaseLock();
}
}
Async iterators syntax
for await(const valueName of iterableObject) {
handler(valueName);
}
Readable streams is to async iterable as array is to sync iterable
https://github.com/whatwg/streams/blob/master/FAQ.md
https://twitter.com/matteocollina/status/978586956761321472?s=19
Not faster, but cleaner
Private fields and methods
https://github.com/tc39/proposal-private-methods
Stage 3 now
Daniel Ehrenberg (Igalia)
For what?
Encapsulation
How we did this before?
Conventions
_ / $$ / this.$vue
Closures
WeakMaps
We need language-level privacy
Private fields
class Foo {
#bar;
methodName() {
this.#bar; // Works
}
}
let foo = new Foo();
foo.#bar; // Invalid!
foo.bar; // Return public field!
Private methods
class User {
#name = ‘’;
setName(value) {
this.#name = value;
this.#render();
}
#render () {
this.el.textContent = this.#name.toString();
}
}
private vs #
Reasons to use # instead of private
Same public and private fields
class Foo {
private baz;
public baz;
method() {
this.baz;
this.baz;
}
}
Reasons to use # instead of private
Public fields in JavaScript can be referenced via this.field or this.['field'].
class Foo {
…
}
const foo = new Foo();
foo['field'] // works just for static fields
Reasons to use # instead of private
You'd need expensive checks
equals(other) { // other could be anything
return this.#x === other.#x && this.#y === other.#y;
}
JAVASCRIPT
Decorators
https://github.com/tc39/proposal-decorators
Stage 2 now
Daniel Ehrenberg (Igalia), Yehuda Katz (Tilde), and Brian Terlson (MicroSoft)
Why we need it?
Сonciseness
Decorators in use
@checkPermission(‘authorized’)
@log
function handler () {
// handle something
}
function handler () {
// check permission
// handle something
// log
}
Decorators are high order functions
@log decorator
function log(f, log) {
return function wrapper() {
log.push(f, arguments);
return f.apply(this, …arguments);
}
}
@defineElement decorator
function decoratorName(target, value, descriptor) {
abstract syntax
}
41/50
Who already use decorators
Moving forward
Optional chaining
https://github.com/tc39/proposal-optional-chaining
Stage 1 now
Claude Pache (no company), Gabe Isenberg (GoDaddy)
What potential errors you could face?
user.address.zipcode
How to prevent it?
if (user && user.address && user.address.zipcode) {
return user.address.zipcode;
}
Optional chainging proposal
if (user?.address?.zipcode){
…
}
Optional chaining syntax
obj?.prop // optional static property access
obj?.[expr] // optional dynamic property access
isClear?.next()
Numeric Separators
https://github.com/tc39/proposal-numeric-separator
Stage 3 now
Christophe Porteneuve(Delicious Insights)
1000000000
At the end of 2017, Kiev has 2933537
inhabitants.
Grouping digits to make long numbers more readable
const inhabitantsOfKiev = 2_933_537;
const price = 120,000.00;
https://esdiscuss.org
Investigate on your own
Create Proposals
Change JS world
Conclusion
66
Contacts
Vitalii Ratushnyi
Email: v.ratyshnij@gmail.com
SkypeID: misreadable

JS Fest 2018. Виталий Ратушный. ES X