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

Tomorrow's Javascript, Today.

Tomorrow's Javascript, Today.

A Crash Course in ES2015 and ES2016 JavaScript given at The Iron Yard.

Jason L Perry

March 02, 2016
Tweet

More Decks by Jason L Perry

Other Decks in Programming

Transcript

  1. 1

  2. 6

  3. (function() { for (var i = 0; i < 2;

    i++) { // ... } console.log(i); })(); // > 2 10
  4. (function() { for (let i = 0; i < 2;

    i++) { // ... } console.log(i); })(); // ! Uncaught ReferenceError: i is not defined 11
  5. 13

  6. var numbers = [42, Math.PI * 2]; var life =

    numbers[0]; var tau = numbers[1]; 15
  7. const [life, ταυ] = [42, Math.PI * 2]; // life

    === 42 // ταυ === 6.283185 16
  8. const numbers = { life: 42, ταυ: Math.PI * 2

    }; let { life, ταυ } = numbers; // life === 42 // ταυ === 6.283185 17
  9. 18

  10. const numbers = { life: 42, ταυ: Math.PI * 2

    }; let { universe, τ } = numbers; // universe === 42 // τ === 6.283185 19
  11. const q = 'questions'; const a = 'answers'; let s

    = `Sometimes the ${q} are complicated and the ${a} are simple.`; 23
  12. 24

  13. var q = 'questions'; var a = 'answers'; var s

    = 'Sometimes the ' + q + ' are complicated and the ' + a + ' are simple.'; 25
  14. 26

  15. const l = `Unless someone like you cares a whole

    awful lot, Nothing is going to get better. It's not.` 28
  16. var l = 'Unless someone like you cares a whole

    awful lot,\n Nothing is going to get better.\n It\'s not.'; 29
  17. var l = 'Unless someone like you cares a whole

    awful lot,\n' + ' Nothing is going to get better.\n' + " It's not."; 30
  18. 31

  19. function fish() { for (var i = 0; i <

    arguments.length; i++) { console.log(arguments[i], 'fish.'); } } fish(...words); // > One fish. // > Two fish. // > Red fish. // > Blue fish. 34
  20. 35

  21. 37

  22. 43

  23. function increase(number, increment) { increment = increment || 1; return

    number + increment; } increase(41, 624); // 665 increase(41); // 42 45
  24. function increase(number, increment = 1) { return number + increment;

    } increase(41, 624); // 665 increase(41); // 42 46
  25. Including, but not limited to: 4 String.prototype.startsWith() 4 String.prototype.endsWith() 4

    String.prototype.contains() 4 String.prototype.repeat() 4 String.prototype.normalize() 51
  26. Including, but not limited to: 4 Array.prototype.find() 4 Array.prototype.findIndex() 4

    Array.prototype.fill() 4 Array.prototype.includes() (ES2016) 53
  27. let inputs = document.querySelectorAll('form input'); for (var i = 0;

    i < inputs.length; i++) { inputs[i].disable = true; } 55
  28. 57

  29. 61

  30. let data = '.uǝɹpןıɥɔ ǝʇǝןosqo ǝɹɐ sʇןnpɐ'; let msg =

    { id: 42, data } { id: 42, data: '.uǝɹpןıɥɔ ǝʇǝןosqo ǝɹɐ sʇןnpɐ' } 67
  31. class Member { constructor(givenName, familyName, rank = 1) { //

    super() this.givenName = givenName; this.familyName = familyName; } promote() { this.rank++; } get displayName() { return `${this.givenName} ${this.familyName} (${'*'.repeat(rank)})`; } } let member = new Member('Jason', 'Perry'); member.promote(); console.log(member.displayName); // > "Jason Perry (**)" 70
  32. import React from 'react'; const App = React.createClass({ propTypes: {

    title: React.PropTypes.string }, // ... }); export default App; 72
  33. import { Component, PropTypes } from 'react'; class App extends

    Component { static propTypes = { title: PropTypes.string } // ... } class Menu extends Component { // ... } export { App, Menu }; import ReactDOM from 'react-dom'; import { App } from './components'; ReactDom.render(App, document.findElementById('root')); 73
  34. { "presets": ["es2015", "react", "stage-0"], "env": { "development": { "plugins":

    [ ["react-transform", { "transforms": [{ "transform": "react-transform-hmr", "imports": ["react"], "locals": ["module"] }] }] ] } } } 83
  35. 84

  36. 4 for...of iteration 4 Promise 4 Symbol 4 Map &

    Set Collections 4 Comprehensions 4 Module loaders 4 Proxy & Reflection APIs 4 Subclassable Built-ins 4 async/await (ES2016) 4 Generators (ES2016) 4 Decorators (ES2016) 4 Better Unicode support 4 New Math & Number APIs 86
  37. 89