Pa Pablo Magaz
ht https://pa pabl bloma
- magaz.com
- m
EC ECMA MASCRIP IPT 2018 18 Y MÁ MÁS ALLÁ
tw twitte tter.com/pablo_m _magaz gi github.com/pma pmagaz
ECMA EC MASCRIP IPT 2018 18 Y M MS ALL Pablo Magaz Pa - - PowerPoint PPT Presentation
ECMA EC MASCRIP IPT 2018 18 Y M MS ALL Pablo Magaz Pa https://pa ht pabl bloma omagaz.com om gi github.com/pma pmagaz tw twitte tter.com/pablo_m _magaz Ar Array fl flatten const nes nested edArray = [1, 2, [3, 4]];
ht https://pa pabl bloma
tw twitte tter.com/pablo_m _magaz gi github.com/pma pmagaz
co const nes
nested edArray = [1, 2, [3, 4]];
]];
nes nested edArray.fl flat()
(); // [ // [1, 2, 3 , 2, 3, 4 , 4]
im import
(`./ ./my my-mo modu dules/ s/${ { dy dynami micModu duleName me }. }.js js`) `);
cons nst fu functionOne = = x => => x; ; cons nst fu functionTwo = = y y => => y; ; le let re result lt = = ‘Hel Hello Codem emotion’ |> |> fu functionOne |> |> fu functionTwo
STAGE 0: : Pr Presentación STAGE 1: : Pr Propuesta f formal STAGE 2: : Bo Borrador STAGE 3: : Can Candidat ato STAGE 4: : Se Seleccionad ado pa para el el standa dard
St Stage ge-0 St Stage ge-1 St Stage ge-2 St Stage ge-3
cons nst it iterab rable le = ‘ = ‘Hel Hello Codem emotion’; ’; cons nst it iterab rable le2 = [ = [‘Hel Hello’, ‘ ‘Codem emotion’]; ’]; fo for (le let x x of
iterab rable le) { ) { cons nsole. e.log log(x); ); } // // H // e e // l l…
cons nst si simpl mpleIterator = = da data => { => { le let cursor = = 0 0; re return rn { nex next: ( () = ) => ( ( cu cursor < < da data.length ? d data[cu cursor++] ++] : : fa false ) }} }} cons nst cons nsumer er = = si simpl mpleIterator([ ([‘Hel Hello', ', ‘Codem emotion’]); ); cons nsole. e.log(cons nsumer er.nex next() ()); // ‘ ‘Hel Hello’ cons nsole. e.log(cons nsumer er.nex next() ()); // ‘ ‘Codem emotion' ' cons nsole. e.log(cons nsumer er.nex next() ()); // f false
cons nst it iterab rable le = [ = [‘Hel Hello’, ‘ ‘Codem emotion’]; ’]; cons nst it iterat rator
= it iterab rable le[Sy Symbol.it iterat rator
](); cons nsole. e.log(it iterat rator
next() ()); // { { va value: ‘ ‘Hel Hello', ', don
lse } cons nsole. e.log(it iterat rator
next() ()); // { { va value: : Codem emotion', ', don
lse } cons nsole. e.log(it iterat rator
next() ()); // { { va value: : und ndefine ned, d done ne: t true } }
fu function* * ge generator() () { yi yield ‘Hel Hello’; ’; yi yield ‘Codem emotion’; ’; } cons nst it iterat rator
= ge generator() (); cons nsole. e.log(it iterat rator
next() ()) // { { va value: ‘ ‘Hel Hello', ', don
lse } cons nsole. e.log(it iterat rator
next() ()) // { { va value: ‘ ‘Codem emotion', ', don
lse } cons nsole. e.log(it iterat rator
next() ()) // { { va value: : und ndefine ned, d done ne: t true } }
async nc fu function my myAsy AsyncFunction() () { cons nst re req = = aw await ait fe fetch(´my myUrl´); ); cons nst da data = = aw await ait re req.te text() (); re return rn JS JSON.pa parse se(d (data.); }
cons nst pr promi mise se1 = = new new Pr Promise(re resolv
=> re resolv
(‘Hel Hello’)); )); cons nst pr promi mise se2 = = new new Pr Promise(re resolv
=> re resolv
(‘Codem emotion’)); )); async nc fu function* * async ncIter erator () () { yi yield aw await ait pr promi mise se1 yi yield aw await ait pr promi mise se2 } } async nc fu function ge getAsyn yncD cData () () { fo for aw await ait (le let x of
ncIter erator() ()) { cons nsole. e.log log(x); ); // Hel Hello, Codem emotion } }
cons nst pr promi mise se1 = = new new Pr Promise(re resolv
=> re resolv
(‘Hel Hello’)); )); cons nst pr promi mise se2 = = new new Pr Promise(re resolv
=> re resolv
(‘Codem emotion’)); )); async nc fu function* * async ncIter erator () () { yi yield aw await ait pr promi mise se1 yi yield aw await ait pr promi mise se2 } } async nc fu function ge getAsyn yncD cData () () { fo for aw await ait (cons nst x of
ncIter erator() ()) { cons nsole. e.log log(x); ); // Hel Hello, Codem emotion } }
cons nst pr promi mise se1 = = new new Pr Promise(re resolv
=> re resolv
(‘Hel Hello’)); )); cons nst pr promi mise se2 = = new new Pr Promise(re resolv
=> re resolv
(‘Codem emotion’)); )); async nc fu function* * async ncIter erator () () { yi yield aw await ait pr promi mise se1 yi yield aw await ait pr promi mise se2 } } cons nst async ncIter erator = = async ncIter erator() () async ncIter erator.nex next() () .th then(va value => => async ncIter erator.nex next() ()) // { { va value: ‘ ‘Hel Hello', ', don
lse } .th then(va value => => async ncIter erator.nex next() ()) // { { va value: ‘ ‘Codem emotion', ', don
lse }
le let { { a, , b, , ...c ...c } = = { { a: ‘ ‘Hel Hello', ', b: ‘ ‘Codem emotion', ', x: : tr true, , y: : fa false }; }; cons nsole. e.log log(a); ); // // Hel Hello cons nsole. e.log log(b); ); // // Codem emotion cons nsole. e.log log(c); ); // { { x x: t true, y y: f false } }
fe fetch(' ('ht https://pa pabl bloma magaz.com/a /api/po post sts’) ’) .th then(re res => { => { pr processR ssRespo sponse se(re res); ); }) }) .ca catch ch(er err => { => { ha hand ndleE eErrors(er err); ); }) }) .fi finally(() (() => { hi hideL eLoading ng() (); }); );
cons nst my myDa Date = = /( /([0 [0-9] 9]{2})-([ ([0-9] 9]{2})-([ ([0-9] 9]{4})/; ; cons nst ma match = = my myDa Date.ex exec ec(‘ (‘23 23-11 11-20 2018’); ); cons nst da day = ma = match[0]; ]; // 0 01 cons nst mo month = ma = match[1]; ]; // 0 03 cons nst ye year = ma = match[2]; ]; // 2 2018
cons nst my myDa Date = = /( /(?<da day>[0 [0-9] 9]{2})-(? (?<mo month>[0 [0-9] 9]{2})-(? (?<ye year>[0 [0-9] 9]{4})/; ; cons nst ma match = = my myDa Date.ex exec ec(‘ (‘23 23-11 11-20 2018’); ); cons nst da day = = ma match.groups. ps.da day; ; // 0 01 cons nst mo month = = ma match.groups. ps.mo month; ; // 0 03 cons nst ye year = = ma match.groups. ps.ye year; ; // 2 2018
(? (?=€) ) // // Lo Lookahead asser ertion 10 100€ (? (?<=€) ) // Lo Lookbe behind asser ertion €10 100
cons nst eu euroPrice = = /( /(?<= <=\u2 u20AC)( )(?<pr price>\d+( d+(?:\.\d+)? d+)?)$ )$/u // // \u2 u20AC € U Unicode de cons nsole. e.log(eu euroPrice.e .exe xec(' ('€10 100') ').gr groups.pr price); ); // 1 100 cons nsole. e.log(eu euroPrice.e .exe xec(‘ (‘10 100€ ') ')); // // nu null
im import
(`./ ./my my-mo modu dules/ s/${ { dy dynami micModu duleName me }. }.js js`) `) .th then(mo modu dule => { => { mo modu dule.do doWi WickedS dStuff() (); }) }) .ca catch ch(er err => => cons nsole. e.log(er err)); ));
cl class My MyClass { _my myFakePrivateProp = 1 = 1; th this._my myFakePrivateMethod() (){ re return rn fa false; } }
cl class My MyClass { a = = 1; ; // // Pu Public pr prope perty #b #b = = 2; ; // // Pr Private pr prope perty #in incre rement() (){ // // Pr Private me method th this.#b #b++; ++; } } cons nst my myObj bject = = new new My MyClass() (); my myObj bject.#b #b; ; // E ERROR! my myObj bject.#in incre rement() (); // E ERROR!
co const nes
nested edArray = [1, 2, [3, 4]];
]];
nes nested edArray.fl
flat() (); // [ // [1, 2, 3 , 2, 3, 4 , 4]
cons nst my myAr Arr =[ =[‘Ba Back t to’,’’, ’,’’,’th the fu future’]; ’]; my myAr Arr.fl flatMap(x => => x. x.spl split(‘ (‘ ‘)); // [ [“Back”,”to”,””,”th the”, ”,”fu future”] ”];
cons nst my myHandl dler = = aw await ait async ncHa Hand ndler er() (); … le let my myModu dule; tr try { my myModu dule = = aw await ait im import
(`./m ./modul ules/$ /${ dy dynami micModu duleName me }. }.js js`) `); } c catch { h { fo foo() (); }
cons nst my myObse bservabl ble = n = new Ob Observa vable(ob
rver => { => {
rver. r.nex next(‘ (‘Hel Hello’); );
rver. r.nex next(‘ (‘Codem emotion!’); );
rver. r.complet ete() (); }); ); Hel Hello Co Comple leted! Codem emotion!
my myObse bservabl ble.su subsc bscribe be({ ({ nex next(va value) { ) { cons nsole. e.log log(va value) } ) }, // // Hel Hello, , Codem emotion! er error(er err) { ) { cons nsole. e.log log(er err) } ) }, // // complet ete() () { cons nsole. e.log log(` (`Done ne!`) `) } // D Done ne! }); );
cons nst do doubl ble = = n => => n * * 2; ; cons nst in incre rement = = n n => => n + + 1; ; le let re result lt = = 5 |> |> do doubl ble |> |> in incre rement |> |> do doubl ble // 2 22
Sl Slides: : pa pablo bloma magaz.com/# /#ta talks
tw twitte tter.com/pablo_m _magaz gi github. b.com
pmaga gaz