Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using JavaScript from the Future in Your Rails Application Today

Using JavaScript from the Future in Your Rails Application Today

ECMAScript 6 has a metric ton of new Ruby-friendly features that make working with JavaScript less painful—including but not limited to: classes, implicitly returning functions, string interpolation, and modules. In this session, we'll take a look at how you can use these features today in your Rails applications.

Steve Kinney

April 23, 2015
Tweet

More Decks by Steve Kinney

Other Decks in Technology

Transcript

  1. Using JavaScript from the Future
    in Your Rails Applications Today
    Steve Kinney, @stevekinney

    View full-size slide

  2. Hi. I'm Steve.
    @stevekinney | [email protected]

    View full-size slide

  3. Every programming language
    has its creation myth.

    View full-size slide

  4. Turbolinks 3

    View full-size slide

  5. Working with JavaScript has
    traditionally involved memorizing
    a bunch of weird tricks and hacks.

    View full-size slide

  6. Towards a better
    language on the client.

    View full-size slide

  7. ECMAScript 6

    View full-size slide

  8. ECMAScript 6 2015

    View full-size slide

  9. So, what's in this
    fancy new language?

    View full-size slide

  10. Classes, modules, array
    comprehension, generators,
    iterators, promises, tail call
    optimization, proxies, string
    interpolation, unicode support, maps,
    sets, symbols, new APIs for primitive
    types, binary and octal literals, slides
    with too many words on them…

    View full-size slide

  11. Firming up the foundation
    of the language.

    View full-size slide

  12. let's have a little
    talk about var.

    View full-size slide

  13. let: It's like var but it does the
    thing you think it's going to do.

    View full-size slide

  14. Turing students ask: “Hey Steve,
    what's your least favorite thing
    about writing JavaScript?”

    View full-size slide

  15. I hate string concatenation with
    the fiery passion of a thousand
    burning suns.

    View full-size slide

  16. Template strings to
    the rescue.

    View full-size slide

  17. JavaScript: ${…}
    Ruby: #{…}

    View full-size slide

  18. Let's play a game.

    View full-size slide

  19. There are some solutions to this
    problem, but none of them are
    going to make you feel good.

    View full-size slide

  20. In ES5, we got
    Function.prototype.bind.

    View full-size slide

  21. In ES6, we get arrow
    functions.

    View full-size slide

  22. What's the point of multi-line
    arrow functions if I need to
    return stuff? What gives?

    View full-size slide

  23. Arrow functions also
    lexically bind this.

    View full-size slide

  24. Let's do some
    refactoring.

    View full-size slide

  25. But, that's not all…

    View full-size slide

  26. In which, JavaScript
    gets some class.

    View full-size slide

  27. This seems brittle.
    Can we refactor this?

    View full-size slide

  28. What about
    inheritance?

    View full-size slide

  29. There is still a bit more
    refactoring that we can do here.

    View full-size slide

  30. Other goodies: class methods and
    properties, inheriting from built-in
    types, computed method names.

    View full-size slide

  31. Splat and spread.

    View full-size slide

  32. Default Arguments

    View full-size slide

  33. How long am I going to have to
    wait until I can use this stuff?

    View full-size slide

  34. You can use all of this
    and more today.

    View full-size slide

  35. Transpilation.

    View full-size slide

  36. ECMAScript 6 2015

    View full-size slide

  37. ECMAScript 7 2016

    View full-size slide

  38. The Birth of a Standard
    • Stage 0 - Strawman
    • Stage 1 - Proposal
    • Stage 2 - Draft
    • Stage 3 - Candidate
    • Stage 4 - Finished

    View full-size slide

  39. Classes, modules, array
    comprehension, generators,
    iterators, promises, tail call
    optimization, proxies, string
    interpolation, unicode support,
    maps, sets, symbols, new APIs
    for primitive types, binary and
    octal literals, slides with too
    many words on them…

    View full-size slide

  40. Thank you!
    Oh, also: Questions?
    All the places on the Internet: @stevekinney
    Come be our friend and mentor our students.
    Hire our students: http://people.turing.io/

    View full-size slide