The Future of JavaScript

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
dherman
April 20, 2012

The Future of JavaScript

SFRails, 4/19/12

dherman

April 20, 2012

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

38 slides
  1. 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:
  2. var  Collections  =  (function()  {        function  Dict()

     {  ...  }        return  {                Dict:  Dict        }; })();
  3. import  {  $  }  from  "jquery.js"; import  {  map,  each

     }  from  "underscore.js"; loaded once, before execution
  4. XHR("foo.txt",  function(foo)  {        XHR("bar.txt",  function(bar)  {  

                 XHR("baz.txt",  function(baz)  {                        setTimeout(function()  {                                status.innerHTML  =                                        foo  +  bar  +  baz;                        },  1000);                });        }); });
  5. 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
  6. 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);                });        }); });
  7. 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);                });        }); });
  8. 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);        }); });
  9. 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);
  10. 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.
  11. 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
  12. var  Point2D  =  struct({        x:  uint32,  

         y:  uint32 }); var  Color  =  struct({        r:  uint8,  g:  uint8,  b:  uint8 });
  13. var  Pixel  =  struct({        point:  Point2D,  

         color:  Color }); var  Triangle  =  array(Pixel,  3);
  14. 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  }  } ])
  15. function  Container()  {        var  secret  =  3;

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

     3  } Container.prototype  =  {        service:  function()  {                if  (this[key]-­‐-­‐)  {                        ...                }        } };
  17. 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}!`
  18. Motivated by use cases. Solve with simple, general, composable features.

    Pieces have to fit together in a cohesive whole.
  19. study the issues study the big picture study the issues

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

More Decks by dherman

Other Decks in Programming