+ All Categories
Home > Software > Javascript Workshop

Javascript Workshop

Date post: 02-Aug-2015
Category:
Upload: assaf-weinberg
View: 253 times
Download: 0 times
Share this document with a friend
Popular Tags:
43
TTS JavaScript Workshop 5/26/2015 @assafweinberg | [email protected]
Transcript
Page 1: Javascript Workshop

TTS JavaScript Workshop5/26/2015

@assafweinberg | [email protected]

Page 2: Javascript Workshop

Agenda

• What is JavaScript?

• 6 Language Fundamentals

• Workshop part 1

• JavaScript in the Browser

• Workshop part 2

Page 3: Javascript Workshop

http://javascript.crockford.com/javascript.html

What is JavaScript?

Page 4: Javascript Workshop
Page 5: Javascript Workshop

Language Fundamentals

https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript

Page 6: Javascript Workshop

Variables

Page 7: Javascript Workshop

JavaScript is… Loosely Typed

Page 8: Javascript Workshop

Loose Typing

Page 9: Javascript Workshop

Type Coercion

Page 10: Javascript Workshop

Coercion

Page 11: Javascript Workshop

Coercion

Page 12: Javascript Workshop

Arrays

Page 13: Javascript Workshop

Objects

Page 14: Javascript Workshop

In JavaScript… Objects are mutable

Page 15: Javascript Workshop

What does it all mean?

Page 16: Javascript Workshop

Is JavaScript Object Oriented?

Page 17: Javascript Workshop

JavaScript is… Not Object Oriented, it’s Functional

Page 18: Javascript Workshop

Functions

Page 19: Javascript Workshop

In JavaScript… Functions are Objects

Page 20: Javascript Workshop

Functions as Properties

Page 21: Javascript Workshop

Functions as Parameters

Page 22: Javascript Workshop

What’s this?

Page 23: Javascript Workshop

In JavaScript… “this” refers to the caller of the function

Page 24: Javascript Workshop

Variable Scope

Page 25: Javascript Workshop

In JavaScript… Functions have scope, blocks do not

Page 26: Javascript Workshop

ScopeClosures

Page 27: Javascript Workshop

ClosuresA function will always have access to variables that were in scope when it was declared

Page 28: Javascript Workshop

JavaScript… Uses Closures (functions have access to variables that were in scope when they were created)

Page 29: Javascript Workshop

6 Lessons in JavaScript… Loosely typedMutable objectsFunctional languageFunctions are ObjectsUses the “this” keyword to refer to callersUses closures

Page 30: Javascript Workshop

WTF Miyagi?WTF Miyagi?

Page 31: Javascript Workshop

It’s Code Time

Page 32: Javascript Workshop

Tournament Rules1. Create an object to model a karate move. A move has a name (e.g. ‘karate chop’,

‘crane kick”, etc.), and a strength score between 1 and 10. Output the move’s name to the console.

2. Create an array with at least 5 karate move objects. Output the name of the 3rd item in the array to the console.

3. Create two objects to model karate fighters. Each fighter has a name, an array of moves, and a function called “performMove” that returns a random move.

4. Create a function called “fight” that takes 2 fighter objects, gets a move from each of them, and outputs a string “[fighter name] did [move name], [fighter 2 name] countered with [move name 2].” to the console. Then return the winning fighter object with the higher strength move. Null if tied.

5. Create a function that takes two fighters and makes them fight until one fighter has won 3 rounds, then outputs “[fightername] wins!” to the console

https://jsfiddle.net/

Page 33: Javascript Workshop

JavaScript in the Browser

Page 34: Javascript Workshop

Runs before page loads

Runs after page loads

Page 35: Javascript Workshop

DOM Manipulation

1. Find something

2. Listen for it to fire an event

3. Edit the DOM based on event

Page 36: Javascript Workshop

window Object

http://www.w3schools.com/jsref/obj_window.asp

Page 37: Javascript Workshop

Document Object Model

http://www.w3schools.com/jsref/obj_window.asp

Editing HTML with JavaScript

Page 38: Javascript Workshop

Find Something

Page 39: Javascript Workshop

Attach Event Handler

Page 40: Javascript Workshop

Another Example

Page 41: Javascript Workshop
Page 42: Javascript Workshop

Browser Exercise1.Create an HTML page and a script that outputs “hello world”

to the console. Import the script onto the page.

2.Create a button and a paragraph. When the button is clicked, the paragraph should say “button clicked”.

3.Change the button click action to display the # of times the button has been clicked in the paragraph.

4.Create an input box and a list on the page. Every time the button is clicked, add a an item to the list with the text from the text input.

* Bonus Problem - Add a delete button to each list item and remove the item when the corresponding button is clicked.

Page 43: Javascript Workshop

Thank You@assafweinberg | [email protected]


Recommended