advanced js css
play

ADVANCED JS & CSS flexb ox ES6 WHAT IS ES6? ES (ECMAScript) is - PowerPoint PPT Presentation

CS498RK SPRING 2020 e s 6 ADVANCED JS & CSS flexb ox ES6 WHAT IS ES6? ES (ECMAScript) is a scripting language standard . JavaScript implements ECMAScript. ES6 means the 6th Edition of ECMAScript. Timelin e 6 years later, ES6! Started in


  1. CS498RK SPRING 2020 e s 6 ADVANCED JS & CSS flexb ox

  2. ES6

  3. WHAT IS ES6? ES (ECMAScript) is a scripting language standard . JavaScript implements ECMAScript. ES6 means the 6th Edition of ECMAScript.

  4. Timelin e 6 years later, ES6! Started in 1997, yearly updates up to 2000 Plethora of new features! 2000: ES4 2019: ES10 2015: ES6 2017: ES8 1998: ES2 (Abandoned) 2020 1997: ES1 2018: ES9 2016: ES7 2009: ES5 1999: ES3 10 years later, ES5. Yearly updates since ES6. Not much new stuff.

  5. ES6 FEATURES Let & Const Rest & Spread Arrow Functions New Array Methods Default Parameters Classes Template Literals Modules Destructuring an d mor e !

  6. LET befor e afte r var x = 1; let x = 1; if (x === 1) { if (x === 1) { var x = 2; let x = 2; console.log(x); // 2 console.log(x); // 2 } } console.log(x); // 2 console.log(x); // 1

  7. CONST befor e afte r var num = 42; const num = 42; try { try { num = 99; num = 99; } catch (err) { } catch (err) { console.log(x); // no err console.log(x); // TypeError } } console.log(num); // 99 console.log(num); // 42

  8. ARROW FUNCTIONS befor e const arr = [1, 2, 3]; const squares = arr.map(function (x) { return x * x }); afte r const arr = [1, 2, 3]; const squares = arr.map(x => x * x );

  9. ARROW FUNCTIONS function MyComponent() { const button = document.getElementById('myButton'); const obj = this; befor e button.addEventListener('click', function () { obj.handleClick(); }); } function MyComponent() { const button = document.getElementById('myButton'); afte r button.addEventListener('click', () => { this.handleClick(); }); }

  10. DEFAULT PARAMETERS befor e afte r function magic(x, y) { function magic(x = 0, y = 0) { x = x || 0; ... y = y || 0; } ... }

  11. TEMPLATE LITERALS befor e function greet(first, last) { console.log('Hello ' + first + ' ' + last + '!'); } afte r function greet(first, last) { console.log(`Hello ${first} ${last}!`); }

  12. TEMPLATE LITERALS befor e afte r var HTML5_SKELETON = const HTML5_SKELETON = ` '<!doctype html>\n' + <!doctype html> '<html>\n' + <html> ' <head>\n' + <head> ' <title></title>\n' + <title></title> ' <meta charset="UTF-8">\n' + <meta charset="UTF-8"> ' </head>\n' + </head> ' <body>\n' + <body> ' </body>\n' + </body> '</html>\n' </html>`

  13. DESTRUCTURING // Assignment const numbers = [1, 2, 3]; const [one, two, three] = numbers; // Works with objects too! // Swapping const obj = { bar: 42, baz: true }; let a = 1; const { bar, baz } = obj; let b = 2; [a, b] = [b, a] // Can also rename variables const { bar: qux, baz: quux } = obj; // Ignoring const foo = () => [1, 2, 3]; let [p, , q] = foo();

  14. REST function secret(first, ...others) { console.log(first); console.log(others); } secret(1, 2, 3, 4, 5); accessin g th e "res t " of th e argument s

  15. SPREAD var arr1 = ['a', 'b']; var arr2 = ['c']; befor e var arr3 = ['d', 'e']; console.log(arr1.concat(arr2, arr3)); // ['a', 'b', 'c', 'd', 'e'] const arr1 = ['a', 'b']; const arr2 = ['c']; afte r const arr3 = ['d', 'e']; console.log([...arr1, ...arr2, ...arr3]); // ['a', 'b', 'c', 'd', 'e']

  16. SPREAD const arr = [1, 2, 3]; const copyOfArr = [...arr]; copyin g a n arra y

  17. NEW ARRAY METHODS const arr = [1, 2, 3]; arr.forEach(n => console.log(n)); // prints 1, 2, 3 arr.map(n => n * n); // returns [1, 4, 9] arr.find(n => n > 1); // returns 2 arr.filter(n => n > 1); // returns [2, 3] arr.some(n => n > 1); // returns true arr.every(n => n > 1); // returns false arr.reduce((n, acc) => acc + n, 0); // returns 6 an d mor e …

  18. CLASSES befor e afte r class Person { function Person(name) { constructor(name) { this.name = name; this.name = name; } } describe() { Person.prototype.describe = function () { return `Person called ${this.name}`; return 'Person called' + this.name; } } }

  19. CLASSES befor e function Employee(name, title) { Person.call(this, name); this.title = title; } Employee.prototype = Object.create(Person.prototype); Employee.prototype.constructor = Employee; Employee.prototype.describe = function () { return Person.prototype.describe.call(this) + ' (' + this.title + ') '; }

  20. CLASSES afte r class Employee extends Person { constructor(name, title) { super(name); this.title = title; } describe() { return `${super.describe()} (${this.title})`; } }

  21. MODULES befor e // ----- lib.js ------- var sqrt = Math.sqrt; function square(x) { return x * x; // ------ main.js ------ } var square = require('./lib').square; function diag(x, y) { var diag = require('./lib').diag; return sqrt(square(x) + square(y)); } console.log(square(11)) // 121 console.log(diag(3, 4)) // 5 module.exports = { sqrt: sqrt, square: square, diag: diag, }

  22. MODULES afte r // ----- lib.js ------- export const sqrt = Math.sqrt; export const square = x => x * x; export const diag = (x, y) => sqrt(square(x) + square(y)); // ------ main.js ------ import { square, diag } from './lib'; console.log(square(11)) // 121 console.log(diag(3, 4)) // 5

  23. MODULES befor e afte r // ------ myFunc.js ------ // ------ myFunc.js ------ module.exports = function () { ... } export default function () { ... } // ------- main.js ------- // ------- main.js ------- var myFunc = require('./myFunc') import myFunc from './myFunc'; myFunc(); myFunc();

  24. RESOURCES http://exploringjs.com/es6/ https://github.com/lukehoban/es6features http://es6-features.org

  25. FLEXBOX

  26. WHAT IS FLEXBOX? Flexbox is a layout model which aims to make it easier to lay out and align elements dynamically. Main Idea: Containers have the ability to adjust their content dynamically. Flexbox is direction-agnostic : can accommodate both horizontal and vertical layouts.

  27. TERMINOLOGY

  28. Containe r /Paren t Prope r tie s

  29. DISPLAY .container { display: flex; }

  30. FLEX-DIRECTION .container { flex-direction: row | row-reverse | column | column-reverse; }

  31. FLEX-WRAP .container { flex-wrap: nowrap | wrap | wrap-reverse; }

  32. FLEX-FLOW .container { flex-flow: <flex-direction> || <flex-wrap>; }

  33. JUSTIFY-CONTENT .container { justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly; }

  34. ALIGN-ITEMS .container { align-items: stretch | flex-start | flex-end | center | baseline; }

  35. ALIGN-CONTENT .container { align-content: flex-start | flex-end | center | stretch | space-between | space-around; }

  36. Ite m /Chil d Prope r tie s

  37. ORDER .item { order: <integer>; }

  38. FLEX-GROW/SHRINK/BASIS .item { flex-grow: <integer>; flex-shrink: <integer>; flex-basis: <length> | auto; }

  39. FLEX .item { flex: none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]; }

  40. ALIGN-SELF .item { align-self: auto | flex-start | flex-end | center | baseline | stretch; }

  41. RESOURCES https://css-tricks.com/snippets/css/a-guide-to-flexbox/ https://developer.mozilla.org/en-US/docs/Learn/CSS/ CSS_layout/Flexbox https://flexboxfroggy.com/

  42. NEXT CLASS: RESPONSIVE DESIGN https://uiuc-web-programming.gitlab.io/sp20/

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend