Slide 1

Slide 1 text

THE FUTURE => OF JAVASCRIPT Dave Herman

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

modules • block scoping • generators • proxies • binary data • destructuring • rest-args & defaults • name objects • custom iteration • comprehensions • string templates • hash tables & weak maps • class syntax • full Unicode • function/object shorthands tl;dr:

Slide 7

Slide 7 text

Great libraries need modules

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

browser

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Generators cleaning up callback spaghetti

Slide 16

Slide 16 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 17

Slide 17 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 18

Slide 18 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 19

Slide 19 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 20

Slide 20 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 21

Slide 21 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 22

Slide 22 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 23

Slide 23 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; }); promise

Slide 24

Slide 24 text

Binary data efficient memory layout and I/O

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

var  Pixel  =  struct({        point:  Point2D,        color:  Color }); var  Triangle  =  array(Pixel,  3);

Slide 27

Slide 27 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 28

Slide 28 text

Name objects first-class, unique property keys

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

Familiar friends… should be no surprise for Rubyists

Slide 32

Slide 32 text

Destructuring: var  [x,  y]  =  getPair(); Parameter defaults: function(x=0,  y=0)  {  } Rest/splat: function(...args)  {  return  args  } Iterators: for  (x  of  keys(obj))  {  } String interpolation: `Hello  ${username}!`

Slide 33

Slide 33 text

The bigger picture…

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Work in the open wiki.ecmascript.org [email protected]

Slide 38

Slide 38 text

Work in the open wiki.ecmascript.org [email protected] Thank you.