SlideShare a Scribd company logo
Are we there yet?
polling & eventing in JavaScript
Ask vs. Tell
Are we
there yet?
Ask vs. Tell
No.
Ask vs. Tell
Are we
there yet?
Ask vs. Tell
No.
Ask vs. Tell
Are we
there yet?
Ask vs. Tell
Are we
there yet?
Ask vs. Tell
NO!!
Ask vs. Tell
Let me know
when we get
there!
Ask vs. Tell
Roger that!
Ask vs. Tell
Ask vs. Tell
Ask vs. Tell
Ask vs. Tell
Ask vs. Tell
Ask vs. Tell
Ask vs. Tell
Ask vs. Tell
Ask vs. Tell
We’re here!
Ask vs. Tell
YAY!!!
Tell, don’t ask.
● More efficient
● Less complex to implement
Telling with Events
Use events to get notified when “something” happens
○ key on keyboard is pressed
○ mouse is moved
○ browser window is resized
○ ...and a lot more!
Hook up your events
document.addEventListener('mousemove', function (e) {
console.log(e.clientX, e.clientY);
});
Example
http://codepen.io/sethmcl/pen/zEGLy
Hook up your events
document.addEventListener('mousemove', function (e) {
console.log(e.clientX, e.clientY);
});
global object provided by the browser, entry point to the
web page which is currently loaded in the browser
Learn more
https://developer.mozilla.org/en-US/docs/Web/API/document
Hook up your events
document.addEventListener('mousemove', function (e) {
console.log(e.clientX, e.clientY);
});
method (function) that we can call to
“register” for a particular event
Learn more
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener
Hook up your events
document.addEventListener('mousemove', function (e) {
console.log(e.clientX, e.clientY);
});
name of event
Learn more
https://developer.mozilla.org/en-US/docs/Web/Reference/Events
Hook up your events
document.addEventListener('mousemove', function (e) {
console.log(e.clientX, e.clientY);
});
function which is called when the event is “fired”
this function is called the “event handler”
Learn more
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers
Hook up your events
document.addEventListener('mousemove', function (e) {
console.log(e.clientX, e.clientY);
});
Learn more
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/mousemove
event object, which contains
information about the event
Keyboard Events
document.addEventListener('keydown', function (e) {
console.log(e.keyCode, e.keyCode);
});
Learn more
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/keydown
Putting it all together
window.addEventListener('resize', function (e) {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Note: resizing the canvas will also clear it
});
Example
http://codepen.io/sethmcl/pen/rsJGh
Homework
Think about the concepts we have
learned so far, and brainstorm an idea
for a game that you can make.
The output of this activity is not code,
but rather a list of ideas and some
drawings (pen and paper, powerpoint,
etc) that describes what you want to
build.

More Related Content

PPTX
Are we there yet? : Moving to an e-only collection development policy for books
NASIG
 
PDF
Personalized Medicine: Are we there yet?
Reid Robison
 
PPTX
GDG On Campus NBNSCOE Web Development Workshop Day 2 : JavaScript and DOM
udaymore742
 
PPT
JavaScript: Events Handling
Yuriy Bezgachnyuk
 
PPTX
Event In JavaScript
ShahDhruv21
 
PPTX
JavaScript_Event_Handling_Updated_______
Captain81145
 
PDF
Events.pdf
stephanedjeukam1
 
PPTX
Introduction to JavaScript DOM and User Input.pptx
GevitaChinnaiah
 
Are we there yet? : Moving to an e-only collection development policy for books
NASIG
 
Personalized Medicine: Are we there yet?
Reid Robison
 
GDG On Campus NBNSCOE Web Development Workshop Day 2 : JavaScript and DOM
udaymore742
 
JavaScript: Events Handling
Yuriy Bezgachnyuk
 
Event In JavaScript
ShahDhruv21
 
JavaScript_Event_Handling_Updated_______
Captain81145
 
Events.pdf
stephanedjeukam1
 
Introduction to JavaScript DOM and User Input.pptx
GevitaChinnaiah
 

Similar to Are we there yet? (15)

PDF
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
PPTX
javascript preye Bokolo's presentation.pptx
godswillsilva111
 
PPTX
JavaScript_Event_Handling_Presentation.pptx
Captain81145
 
PPTX
types of events in JS
chauhankapil
 
PPTX
5 .java script events
chauhankapil
 
PPTX
J Query Presentation of David
Arun David Johnson R
 
PPTX
DOM_and_JS_Events_Presentation_simpleandShort.pptx
shivaninegi0435
 
PPTX
DHTML - Events & Buttons
Deep Patel
 
PPT
Document_Object_Model_in_javaScript..................................ppt
rahamatmandal2005
 
PDF
JavaScript From Scratch: Events
Michael Girouard
 
PPT
Javascript dom event
Bunlong Van
 
PPTX
JS basics
Mohd Saeed
 
PPTX
Web programming
Subha Selvam
 
PDF
Web 5 | JavaScript Events
Mohammad Imam Hossain
 
PPTX
Web designing unit 4
Dr. SURBHI SAROHA
 
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
javascript preye Bokolo's presentation.pptx
godswillsilva111
 
JavaScript_Event_Handling_Presentation.pptx
Captain81145
 
types of events in JS
chauhankapil
 
5 .java script events
chauhankapil
 
J Query Presentation of David
Arun David Johnson R
 
DOM_and_JS_Events_Presentation_simpleandShort.pptx
shivaninegi0435
 
DHTML - Events & Buttons
Deep Patel
 
Document_Object_Model_in_javaScript..................................ppt
rahamatmandal2005
 
JavaScript From Scratch: Events
Michael Girouard
 
Javascript dom event
Bunlong Van
 
JS basics
Mohd Saeed
 
Web programming
Subha Selvam
 
Web 5 | JavaScript Events
Mohammad Imam Hossain
 
Web designing unit 4
Dr. SURBHI SAROHA
 
Ad

More from Seth McLaughlin (10)

PDF
Building testable chrome extensions
Seth McLaughlin
 
PDF
Join the darkside: Selenium testing with Nightwatch.js
Seth McLaughlin
 
PDF
Chapter 2: What's your type?
Seth McLaughlin
 
PDF
Chapter 1: Communicating with Your Computer
Seth McLaughlin
 
PDF
JavaScript State of Mind
Seth McLaughlin
 
PDF
Get Moving! (with HTML5 canvas)
Seth McLaughlin
 
PDF
Hello, Canvas.
Seth McLaughlin
 
PDF
Testing Web Applications
Seth McLaughlin
 
PDF
Introduction to Venus.js
Seth McLaughlin
 
PDF
Front-End Testing: Demystified
Seth McLaughlin
 
Building testable chrome extensions
Seth McLaughlin
 
Join the darkside: Selenium testing with Nightwatch.js
Seth McLaughlin
 
Chapter 2: What's your type?
Seth McLaughlin
 
Chapter 1: Communicating with Your Computer
Seth McLaughlin
 
JavaScript State of Mind
Seth McLaughlin
 
Get Moving! (with HTML5 canvas)
Seth McLaughlin
 
Hello, Canvas.
Seth McLaughlin
 
Testing Web Applications
Seth McLaughlin
 
Introduction to Venus.js
Seth McLaughlin
 
Front-End Testing: Demystified
Seth McLaughlin
 
Ad

Recently uploaded (20)

PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
oapresentation.pptx
mehatdhavalrajubhai
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Activate_Methodology_Summary presentatio
annapureddyn
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 

Are we there yet?

  • 1. Are we there yet? polling & eventing in JavaScript
  • 2. Ask vs. Tell Are we there yet?
  • 4. Ask vs. Tell Are we there yet?
  • 6. Ask vs. Tell Are we there yet?
  • 7. Ask vs. Tell Are we there yet?
  • 9. Ask vs. Tell Let me know when we get there!
  • 21. Tell, don’t ask. ● More efficient ● Less complex to implement
  • 22. Telling with Events Use events to get notified when “something” happens ○ key on keyboard is pressed ○ mouse is moved ○ browser window is resized ○ ...and a lot more!
  • 23. Hook up your events document.addEventListener('mousemove', function (e) { console.log(e.clientX, e.clientY); }); Example http://codepen.io/sethmcl/pen/zEGLy
  • 24. Hook up your events document.addEventListener('mousemove', function (e) { console.log(e.clientX, e.clientY); }); global object provided by the browser, entry point to the web page which is currently loaded in the browser Learn more https://developer.mozilla.org/en-US/docs/Web/API/document
  • 25. Hook up your events document.addEventListener('mousemove', function (e) { console.log(e.clientX, e.clientY); }); method (function) that we can call to “register” for a particular event Learn more https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener
  • 26. Hook up your events document.addEventListener('mousemove', function (e) { console.log(e.clientX, e.clientY); }); name of event Learn more https://developer.mozilla.org/en-US/docs/Web/Reference/Events
  • 27. Hook up your events document.addEventListener('mousemove', function (e) { console.log(e.clientX, e.clientY); }); function which is called when the event is “fired” this function is called the “event handler” Learn more https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers
  • 28. Hook up your events document.addEventListener('mousemove', function (e) { console.log(e.clientX, e.clientY); }); Learn more https://developer.mozilla.org/en-US/docs/Web/Reference/Events/mousemove event object, which contains information about the event
  • 29. Keyboard Events document.addEventListener('keydown', function (e) { console.log(e.keyCode, e.keyCode); }); Learn more https://developer.mozilla.org/en-US/docs/Web/Reference/Events/keydown
  • 30. Putting it all together window.addEventListener('resize', function (e) { canvas.width = window.innerWidth; canvas.height = window.innerHeight; // Note: resizing the canvas will also clear it }); Example http://codepen.io/sethmcl/pen/rsJGh
  • 31. Homework Think about the concepts we have learned so far, and brainstorm an idea for a game that you can make. The output of this activity is not code, but rather a list of ideas and some drawings (pen and paper, powerpoint, etc) that describes what you want to build.