Slide 1

Slide 1 text

Advanced JavaScript Workshop Jennifer Bland wifi: The Creative Circus pass: madhatter

Slide 2

Slide 2 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Housekeeping • You must have node.js installed - https://nodejs.org • You must have a text editor installed • Clone repo from GitHub https://github.com/ratracegrad/advanced-javascript-workshop

Slide 3

Slide 3 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland What We Will Cover • What is new in EcmaScript 2016 • What is new in EcmaScript 2017 • Recursion • Inheritance • PrototypeChain

Slide 4

Slide 4 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland EcmaScript • What is it • When are updates created to the language • Version numbering

Slide 5

Slide 5 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland EcmaScript 2016 • Array.prototype.includes() • Exponent operator

Slide 6

Slide 6 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Array.prototype.includes() • Checks the array for the value passed as an argument • returns true or false • Replaces Array.prototype.indexOf()

Slide 7

Slide 7 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland

Slide 8

Slide 8 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Example

Slide 9

Slide 9 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Classwork 1 • Find out if Array.prototype.includes() works with just numbers or will it work with strings?

Slide 10

Slide 10 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Classwork 2 • How does Array.prototype.includes() handle NaN compared to indexOf?

Slide 11

Slide 11 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Exponent Operator • Adds a new arithmetic operator - ** • Same purpose as Math.pow()

Slide 12

Slide 12 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Math.pow()

Slide 13

Slide 13 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Example

Slide 14

Slide 14 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland EcmaScript 2017 • Async Functions • Object methods - .values() and .entries() • String padding • Recursion • Inheritance and the prototype chain

Slide 15

Slide 15 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Object.values() • Objects are make up of key-value pairs • Object.keys() was already available to us • Access all the values of an object • Returns values in an array

Slide 16

Slide 16 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Object.values() • Example

Slide 17

Slide 17 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Object.entries() • This combines both the key and value into an array

Slide 18

Slide 18 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Example

Slide 19

Slide 19 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Classwork

Slide 20

Slide 20 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland String Padding • Two new method added to String prototype • padStart - ‘string’.padStart(targetLength, padString) • padEnd - ‘string’.padEnd(targetLength, padString)

Slide 21

Slide 21 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Classwork

Slide 22

Slide 22 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Object.getOwnPropertyDescriptors() • Returns all own (non-inherited) property descriptors of an object • Attributes of the return object can be: • value • writable • get • set

Slide 23

Slide 23 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Example

Slide 24

Slide 24 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Async Functions • Async and Await • Async functions always return a promise • Await keyword may only be used in functions with the async keyword • non blocking code

Slide 25

Slide 25 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Example • Example

Slide 26

Slide 26 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Recursion • A recursive function is one that calls itself repeatedly until it arrives at a result • Most loops can be written in a recursive style

Slide 27

Slide 27 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland

Slide 28

Slide 28 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Recursion function factorial(x) { // TERMINATION // BASE // RECURSION }

Slide 29

Slide 29 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Recursion function factorial(x) { // TERMINATION // BASE // RECURSION }

Slide 30

Slide 30 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Inheritance and Prototype Chain • JavaScript is a prototype-based language • Every object has an internal property called Prototype • let x = {}; • Object.getPrototypeOf(x);

Slide 31

Slide 31 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Inheritance and Prototype Chain When you attempt to access a property or method of an object, JavaScript will first search on the object itself, and if it is not found it will search the object’s Prototype. If after searching both the object and its Prototype and still not match is found. JavaScript will check the prototype of the linked object, and continue searching until the end of the prototype chain is reached. At the end of the prototype chain is Object.prototype. All objects inherit the properties and methods of Object. Any attempt to search beyond the end of the chain results in null.

Slide 32

Slide 32 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Inheritance and Prototype Chain Inheritance refers to an object’s ability to access methods and other properties from another object. Objects can inherit things from other objects. Inheritance in JavaScript works through something called prototypes

Slide 33

Slide 33 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Inheritance and Prototype Chain In JavaScript, all functions are also objects, which means that they can have properties. All functions have a property called ‘prototype’, which is also an object. function foo() {}; typeof foo.prototype

Slide 34

Slide 34 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Constructors In JavaScript, there is really no difference between a “regular” function and a “constructor” function. They are actually the same. As a convention, functions that are meant to be used as constructors are generally capitalized.

Slide 35

Slide 35 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Constructors

Slide 36

Slide 36 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Differential Inheritance JavaScript uses an inheritance model called “differential inheritance”. Methods are not copied from parent to child. Instead children have an “invisible link” back to their parent object. For example, fido does not actually have its own method called bark() fido.hasOwnProperty(‘bark’)

Slide 37

Slide 37 text

Advanced JavaScript Workshop ------ Women Who Code Atlanta ------ Jennifer Bland Prototype Chain What actually happens when I write fido.bark() is this: 1. JavaScript looks for a property called bark on our fido object 2. It doesn’t find one so it looks “up the prototype chain” to fido’s parent which is Dog.prototype 3. It finds Dog.prototype.bark and calls it with ‘this’ bound to fido