Slide 1

Slide 1 text

THE FUTURE OF JAVASCRIPT SO BRIGHT IT BURNS

Slide 2

Slide 2 text

Hi, I’m dherman @littlecalculist

Slide 3

Slide 3 text

I — JavaScript and I love the language it almost is...

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

tl;dr

Slide 7

Slide 7 text

TIER 1 AWESOMENESS modules • block scoping • generators • proxies • binary data • destructuring • rest-args & defaults TIER 2 AWESOMENESS name objects • custom iteration • comprehensions • string templates • hash tables & weak maps

Slide 8

Slide 8 text

Great languages deserve great libraries and that means modules

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

browser

Slide 11

Slide 11 text

var  Collections  =  (function()  {        function  Dict()  {  ...  }        return  {                Dict:  Dict        }; })();

Slide 12

Slide 12 text

“The human compiler, at work.” — Paul Graham “The sincerest form of feature request.” — someone?

Slide 13

Slide 13 text

module  Collections  {        export  function  Dict()  {  ...  } }

Slide 14

Slide 14 text

import  {  $  }  from  "jquery.js"; import  {  map,  each  }  from  "underscore.js";

Slide 15

Slide 15 text

import  {  $  }  from  "jquery.js"; import  {  map,  each  }  from  "underscore.js"; loaded once, before execution

Slide 16

Slide 16 text

let is the new var block scoping (at long, long last)

Slide 17

Slide 17 text

for  (i  =  0;  i  <  a.length;  i++)  {        var  x  =  a[i];        x.onclick  =  function()  {  x.toggle()  }; }

Slide 18

Slide 18 text

for  (i  =  0;  i  <  a.length;  i++)  {        let  x  =  a[i];        x.onclick  =  function()  {  x.toggle()  }; }

Slide 19

Slide 19 text

Generator functions an alternative to callback spaghetti

Slide 20

Slide 20 text

function*  counter()  {        yield  1;        yield  2;        yield  3; } var  g  =  counter(); alert(g.next());  //  1 alert(g.next());  //  2 alert(g.next());  //  3

Slide 21

Slide 21 text

XHR("foo.txt",  function(foo)  {        XHR("bar.txt",  function(bar)  {                XHR("baz.txt",  function(baz)  {                        setTimeout(function()  {                                status.innerHTML  =                                        foo  +  bar  +  baz;                        },  1000);                });        }); });

Slide 22

Slide 22 text

XHR("foo.txt",  function(foo)  {        XHR("bar.txt",  function(bar)  {                XHR("baz.txt",  function(baz)  {                        setTimeout(function()  {                                status.innerHTML  =                                        foo  +  bar  +  baz;                        },  1000);                });        }); }); pyramid of doom

Slide 23

Slide 23 text

function  onTimeout(foo,  bar,  baz)  {        status.innerHTML  =  foo  +  bar  +  baz; } XHR("foo.txt",  function(foo)  {        XHR("bar.txt",  function(bar)  {                XHR("baz.txt",  function(baz)  {                        setTimeout(function()  {                                onTimeout(foo,  bar,  baz);                        },  1000);                });        }); });

Slide 24

Slide 24 text

function  onTimeout(foo,  bar,  baz)  {        status.innerHTML  =  foo  +  bar  +  baz; } function  onBaz(foo,  bar,  baz)  {        setTimeout(function()  {                onTimeout(foo,  bar,  baz);        },  1000); } XHR("foo.txt",  function(foo)  {        XHR("bar.txt",  function(bar)  {                XHR("baz.txt",  function(baz)  {                        onBaz(foo,  bar,  baz);                });        }); });

Slide 25

Slide 25 text

function  onTimeout(foo,  bar,  baz)  {        status.innerHTML  =  foo  +  bar  +  baz; } function  onBaz(foo,  bar,  baz)  {        setTimeout(function()  {                onTimeout(foo,  bar,  baz);        },  1000); } function  onBar(foo,  bar)  {        XHR("baz.txt",  function(baz)  {                onBaz(foo,  bar,  baz);        }); } XHR("foo.txt",  function(foo)  {        XHR("bar.txt",  function(bar)  {                onBar(foo,  bar);        }); });

Slide 26

Slide 26 text

function  onTimeout(foo,  bar,  baz)  {        status.innerHTML  =  foo  +  bar  +  baz; } function  onBaz(foo,  bar,  baz)  {        setTimeout(function()  {                onTimeout(foo,  bar,  baz);        },  1000); } function  onBar(foo,  bar)  {        XHR("baz.txt",  function(baz)  {                onBaz(foo,  bar,  baz);        }); } function  onFoo(foo)  {        XHR("bar.txt",  function(bar)  {                onBar(foo,  bar);        }); } XHR("foo.txt",  onFoo);

Slide 27

Slide 27 text

Pour 1/2 cup water into pan. When you’re done: Bring water to boil. When that’s done: Lower heat and add rice. After 15 minutes: Turn off heat and serve.

Slide 28

Slide 28 text

spawn(function*()  {        var  foo  =  yield  read("foo.txt"),                bar  =  yield  read("bar.txt"),                baz  =  yield  read("baz.txt");        yield  sleep(1000);        status.innerHTML  =  foo  +  bar  +  baz; });

Slide 29

Slide 29 text

Proxies meta-programming for fun and profit

Slide 30

Slide 30 text

var  p  =  new  Proxy(obj,  {        get:  function(...)  {  ...  },        set:  function(...)  {  ...  },        delete:  function(...)  {  ...  },        ... });

Slide 31

Slide 31 text

Bits, bytes and blobs binary file and network I/O

Slide 32

Slide 32 text

var  Point2D  =  new  StructType({        x:  uint32,        y:  uint32 }); var  Color  =  new  StructType({        r:  uint8,  g:  uint8,  b:  uint8 });

Slide 33

Slide 33 text

var  Pixel  =  new  StructType({        point:  Point2D,        color:  Color }); var  Triangle  =  new  ArrayType(Pixel,  3);

Slide 34

Slide 34 text

new  Triangle([        {  point:  {  x:  0,  y:  0  },            color:  {  r:  255,  g:  255,  b:  255  }  },        {  point:  {  x:  5,  y:  5  },            color:  {  r:  128,  g:  0,  b:  0  }  },        {  point:  {  x:  10,  y:  0  },            color:  {  r:  0,  g:  0,  b:  128  }  } ])

Slide 35

Slide 35 text

Destructuring try it, you’ll like it

Slide 36

Slide 36 text

var  {  r,  g,  b  }  =  thing.color; var  [x,  y]  =  circle.center; [a,  b]  =  [b,  a];

Slide 37

Slide 37 text

function  div({  width,  height,  border  })  {        ... }

Slide 38

Slide 38 text

Rest-args and defaults death to the arguments object!

Slide 39

Slide 39 text

function  f(i,  j,  ...rest)  {        return  rest.slice(i,  j); }

Slide 40

Slide 40 text

array.push(thing1,  thing2,  ...moarThings); var  shape  =  new  Shape(...points);

Slide 41

Slide 41 text

function  img(src,  width=320,  height=240)  {        ... }

Slide 42

Slide 42 text

function  img({  src,                              width=320,                              height=240  })  {        ... }

Slide 43

Slide 43 text

Name objects first-class, unique property keys

Slide 44

Slide 44 text

function  Container()  {        var  secret  =  3;        this.service  =  function()  {                if  (secret-­‐-­‐)  {                        ...                }        }; }

Slide 45

Slide 45 text

var  key  =  Name.create("secret"); function  Container()  {  this[key]  =  3  } Container.prototype  =  {        service:  function()  {                if  (this[key]-­‐-­‐)  {                        ...                }        } };

Slide 46

Slide 46 text

Custom object iteration taming the for-in loop

Slide 47

Slide 47 text

for  (x  in  [3,  4,  5])          //  0,  1,  2  (d’oh) for  (x  of  [3,  4,  5])          //  3,  4,  5 for  (x  of  keys(o))              //  keys  in  o for  (x  of  values(o))          //  values  of  o for  ([k,  v]  of  items(o))  //  props  of  o

Slide 48

Slide 48 text

import  iterate  from  "@iter"; obj[iterate]  =  function()  {        return  {                next:  function()  {  ...  }        } } for  (x  of  obj)  {  ...  }

Slide 49

Slide 49 text

Comprehensions beautiful array processing

Slide 50

Slide 50 text

[  x  *  y  for  (x  of  obj1)  for  (y  of  obj2)  ] (  x  *  y  for  (x  of  obj1)  for  (y  of  obj2)  )

Slide 51

Slide 51 text

String templates untangling string formatting code

Slide 52

Slide 52 text

"

\nohai,  "  + firstName  +  "  "  +  lastName  + "\n

"

Slide 53

Slide 53 text

`

ohai,  ${firstName}  ${lastName}

`

Slide 54

Slide 54 text

safeHTML`

ohai,  ${firstName}  ${lastName}

`

Slide 55

Slide 55 text

Object-keyed tables hash tables and weak maps

Slide 56

Slide 56 text

var  scores  =  new  Map(); var  player1  =  {  ...  }; scores.set(player1,  0); scores.get(player1)  //  0

Slide 57

Slide 57 text

var  markers  =  new  WeakMap(); var  tile  =  new  Tile(...); var  results  =  [...]; tiles.set(tile,  results);

Slide 58

Slide 58 text

There is a bigger picture.

Slide 59

Slide 59 text

“Be a better language for: a. complex apps b. libraries c. code generators”

Slide 60

Slide 60 text

Motivated by use cases. Solve with simple, general, composable features. Pieces have to fit together in a cohesive whole.

Slide 61

Slide 61 text

study the issues study the big picture study the issues again study the big picture again study the issues again SHIP IT!

Slide 62

Slide 62 text

Work in the open wiki.ecmascript.org es-discuss

Slide 63

Slide 63 text

How soon is now?

Slide 64

Slide 64 text

We (Ecma) are working hard and fast on the spec. We (vendors) are prototyping and shipping features now. Transpilers as language shims: Traceur, Narcissus

Slide 65

Slide 65 text

No content