SlideShare a Scribd company logo
JavaScript Used by many.  Understood by few. Matthew Batchelder Lead Developer, Plymouth State University
Agenda JavaScript: What it is and isn't What is the DOM? What is AJAX? jQuery FTW! Manipulating page elements (the DOM) in sweet ways Simplified AJAX Other Coolness Pluggability jQuery in myPlymouth
“ The World’s Most Misunderstood Programming Language” -Douglas Crockford
Complaints “JavaScript is not a language I know” “The browser programming experience is awful.” “It’s not fast enough.” “The language is just a pile of mistakes.” -Douglas Crockford
JS: What is it? Client Side Scripting language.
JS: What is it? JavaScript is  not  Java.  In fact, it has succeeded where Java has failed.
JS: What is it? Prototypal Inheritance Dynamic Object Lambda Functions Loosely Typed C Family Syntax Java-like Conventions Perl Regular Expressions
JS: The Bad Stuff Global Variables + is used for adding AND concatenation Semicolon insertion Typeof Phony arrays == and != False, null, undefined, NaN
== and != ‘’  == ‘0’ //false 0 == ‘’ //true 0 == ‘0’ //true false == ‘false’ // false false == ‘0’ //true false == undefined //false false == null //false null == undefined //true “  \t\r\n “ == 0 //true
JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals A function is an Object Too! var bob = function(){ alert(‘cheeseypoof’); }
JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals At any time you can take an object and dynamically add a property to it. // create an object var ohhai2u = new Object(); // then do ohhai2u.foo = ‘bar’; // you can now do alert(ohhai2u.foo);
JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals Flexibility in not defining variable types…just like PHP.
JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals You don’t need to use “new” syntax to define objects: // create an object var ohhai2u = {}; // then do ohhai2u.foo = ‘bar’; // ohhai2u now looks like this {foo: ‘bar’}
Inheritance Prototypical Inheritance Class free Objects inherit from other objects An object contains only what makes it different from inherited objects.
JS: Sweetness JavaScript is Sandboxed Client Side Data Transport (JSON vs XML) UI Manipulation … DOM!
What is the DOM? DOM == Document Object Model The DOM is  hierarchical <html> <head> <title>Example JS Page</title> </head> <body> <form id=“some_form”> <input type=“text” name=“bork”/> <input type=“submit” value=“Go”/> </form> </body> </html>
Finding DOM Elements document.getElementById() returns a specific element document.getElementByTag() returns an array of elements
DOM Element Attributes nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument 1 = an HTML element 2 = an element attribute 3 = text 8 = an HTML comment 9 = a document 10 = a document type definition DOM Attributes Node Types Here’s a  good article  that uses these.
Manipulating the DOM Dynamically creating and adding elements document.createElement appendChild example
innerHTML Why go through the trouble of creating Nodes? More efficient Easier example
Events Click Dblclick Mousedown Mouseup Mouseover Mousemove Mouseout Keypress Keydown Keyup Select Change Submit Reset Focus Blur Load Unload  Abort Error Resize Scroll Mouse Keyboard Frame/Object Form
JS: Usage Drop this puppy in your page:  <html> <head> <title>Example JS Page</title> <script type=“text/javascript”> // javascript code goes here </script> </head> <body> … </body> </html>
Simple Alert Box <html> <head> <title>Example Message Box Page</title> <script type=“text/javascript”> alert(‘I like butter’); </script> </head> <body> … </body> </html>
Confirm Box Bound to an Event <html> <head> <title>Example Message Box Page</title> <script type=&quot;text/javascript&quot;> function doLoad() { document.getElementById('sweet-link').addEventListener(‘click’, confirmClick, false); }//end doLoad function confirmClick() { return confirm(‘Are you sure you wish to go to that link?’); }//end confirmClick window.addEventListener(‘load’, doLoad, false); </script> </head> <body> <a id=&quot;sweet-link&quot; href=&quot;http://borkweb.com&quot;>BorkWeb</a> </body> </html> example
Hiding/Displaying Elements Element visibility is a nice use of events and DOM manipulation example
AJAX AJAX  (Asychronous Javascript and XML) Gives you the ability to load content  dynamically ! Loading content on demand Possible usability Issues Possible performance  problems  and  benefits Limitation : No AJAX calls beyond the sandbox. Note: The way around this is with  XSS  (Cross Site Scripting)…which can be dangerous if done poorly.
Ajax: XMLHttpRequest Loading content on demand: <script type=&quot;text/javascript&quot;> function ajax(url, vars, callbackFunction){  var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject(&quot;MSXML2.XMLHTTP.3.0&quot;);  request.open(&quot;GET&quot;, url, true); request.setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);  request.onreadystatechange = function(){ if (request.readyState == 4 && request.status == 200){ if (request.responseText){ callbackFunction(request.responseText); } } }; request.send(vars); }//end ajax function out(text){ document.getElementById('content').innerHTML = text; }//end out function ajaxCall(){ ajax('http://borkweb.com/examples/js_workshop/dynamic_content1.html','',out);return false; }//end ajaxCall  function doLoad(){ document.getElementById('sweet-link').addEventListener('click', ajaxCall, false); }//doLoad  window.addEventListener('load', doLoad, false);  </script> example
WAIT!!!!!!!!!!!!! Things can actually be a bit easier. How much?  Well most of the above.
WTF? jQuery.  That’s what we use on campus.  It is awesome.
What is jQuery? jQuery is a sweet JavaScript Library Its Mantra:  Find stuff and do stuff with it Focuses on simplicity Get it  here Check out the  docs
Finding Elements Say goodbye to document.getElementById() and document.getElementByTag() Say hello to: $() Uses  CSS Selectors  to find elements and returns them as an array of elements.
Finding Elements With $ $(‘a’) $(‘.class’) $(‘#id’) $(‘.content div’) $(‘input[name=bork]’) $(‘input:first’) Here’s an  example . Check out the selector syntax for more info.
Lets do some of the stuff we already did… Adding Text Fields Toggling Element Visibility Ajax Content
jQuery Coolness Browser data $.browser Effects Sliding Fading Animating Chaining $(‘a’).click(function(){alert(‘hello’); return false;}).css(‘font-weight’,’bold’).fadeOut(‘slow’);
jQuery Plugins Pluggable!  Additional jQuery functionality added by including  jQuery plugins .
jQuery in myPlymouth Go Sidebar Bookmarks Tab Stack Etc… Check out the  source .
Before We Start! Important tools to have Use Firefox  Firebug JS Debugging FTW Web Developer Toolbar (handy) A sexy text editor (not notepad)
The End. Resources:  JS: The Good Parts ,  Slide Examples ,  jQuery ,  Image Sprites ,  Mega Man !

More Related Content

What's hot (18)

PPTX
Javascript inside Browser (DOM)
Vlad Mysla
 
PDF
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
tutorialsruby
 
PPT
Javascript by geetanjali
Geetanjali Bhosale
 
PPTX
Introduction to java_script
Basavaraj Hampali
 
PDF
JAVA SCRIPT
Mohammed Hussein
 
DOCX
Javascript tutorial
Abhishek Kesharwani
 
PDF
lect9
tutorialsruby
 
PPT
Think jQuery
Ying Zhang
 
PPT
Eugene Andruszczenko: jQuery
Refresh Events
 
PDF
JavaScript DOM Manipulations
Ynon Perek
 
PPTX
Java Script
Dr. SURBHI SAROHA
 
PDF
Javascript
Momentum Design Lab
 
PPT
Java Script
siddaram
 
PDF
Javascript, DOM, browsers and frameworks basics
Net7
 
PDF
Web Projects: From Theory To Practice
Sergey Bolshchikov
 
PPT
Java script
umesh patil
 
PPT
JavaScript Missing Manual, Ch. 1
Gene Babon
 
DOC
Basics java scripts
ch samaram
 
Javascript inside Browser (DOM)
Vlad Mysla
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
tutorialsruby
 
Javascript by geetanjali
Geetanjali Bhosale
 
Introduction to java_script
Basavaraj Hampali
 
JAVA SCRIPT
Mohammed Hussein
 
Javascript tutorial
Abhishek Kesharwani
 
Think jQuery
Ying Zhang
 
Eugene Andruszczenko: jQuery
Refresh Events
 
JavaScript DOM Manipulations
Ynon Perek
 
Java Script
Dr. SURBHI SAROHA
 
Java Script
siddaram
 
Javascript, DOM, browsers and frameworks basics
Net7
 
Web Projects: From Theory To Practice
Sergey Bolshchikov
 
Java script
umesh patil
 
JavaScript Missing Manual, Ch. 1
Gene Babon
 
Basics java scripts
ch samaram
 

Similar to Javascript 2009 (20)

PPTX
Java script
Rajkiran Mummadi
 
PPTX
Java Script - A New Look
rumsan
 
PPS
Advisor Jumpstart: JavaScript
dominion
 
PPT
Reversing JavaScript
Roberto Suggi Liverani
 
PPT
UNIT 3.ppt
MadhurRajVerma1
 
PPT
Easy javascript
Bui Kiet
 
PDF
JavaScript
Bharti Gupta
 
PPTX
UNIT 1 (7).pptx
DrDhivyaaCRAssistant
 
PPT
Learn javascript easy steps
prince Loffar
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
DOC
javscript
rcc1964
 
ODP
JavaScript and jQuery Fundamentals
BG Java EE Course
 
PPTX
wp-UNIT_III.pptx
GANDHAMKUMAR2
 
PDF
Intro to JavaScript
Jussi Pohjolainen
 
PPT
Js mod1
VARSHAKUMARI49
 
PPTX
Javascript
Mozxai
 
PPT
Java Script Programming on Web Application
SripathiRavi1
 
PDF
lect4
tutorialsruby
 
PDF
lect4
tutorialsruby
 
Java script
Rajkiran Mummadi
 
Java Script - A New Look
rumsan
 
Advisor Jumpstart: JavaScript
dominion
 
Reversing JavaScript
Roberto Suggi Liverani
 
UNIT 3.ppt
MadhurRajVerma1
 
Easy javascript
Bui Kiet
 
JavaScript
Bharti Gupta
 
UNIT 1 (7).pptx
DrDhivyaaCRAssistant
 
Learn javascript easy steps
prince Loffar
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
javscript
rcc1964
 
JavaScript and jQuery Fundamentals
BG Java EE Course
 
wp-UNIT_III.pptx
GANDHAMKUMAR2
 
Intro to JavaScript
Jussi Pohjolainen
 
Javascript
Mozxai
 
Java Script Programming on Web Application
SripathiRavi1
 
Ad

Recently uploaded (20)

PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Ad

Javascript 2009

  • 1. JavaScript Used by many. Understood by few. Matthew Batchelder Lead Developer, Plymouth State University
  • 2. Agenda JavaScript: What it is and isn't What is the DOM? What is AJAX? jQuery FTW! Manipulating page elements (the DOM) in sweet ways Simplified AJAX Other Coolness Pluggability jQuery in myPlymouth
  • 3. “ The World’s Most Misunderstood Programming Language” -Douglas Crockford
  • 4. Complaints “JavaScript is not a language I know” “The browser programming experience is awful.” “It’s not fast enough.” “The language is just a pile of mistakes.” -Douglas Crockford
  • 5. JS: What is it? Client Side Scripting language.
  • 6. JS: What is it? JavaScript is not Java. In fact, it has succeeded where Java has failed.
  • 7. JS: What is it? Prototypal Inheritance Dynamic Object Lambda Functions Loosely Typed C Family Syntax Java-like Conventions Perl Regular Expressions
  • 8. JS: The Bad Stuff Global Variables + is used for adding AND concatenation Semicolon insertion Typeof Phony arrays == and != False, null, undefined, NaN
  • 9. == and != ‘’ == ‘0’ //false 0 == ‘’ //true 0 == ‘0’ //true false == ‘false’ // false false == ‘0’ //true false == undefined //false false == null //false null == undefined //true “ \t\r\n “ == 0 //true
  • 10. JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals A function is an Object Too! var bob = function(){ alert(‘cheeseypoof’); }
  • 11. JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals At any time you can take an object and dynamically add a property to it. // create an object var ohhai2u = new Object(); // then do ohhai2u.foo = ‘bar’; // you can now do alert(ohhai2u.foo);
  • 12. JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals Flexibility in not defining variable types…just like PHP.
  • 13. JS: Good Stuff Lambda Functions Dynamic Objects Loose Typing Object Literals You don’t need to use “new” syntax to define objects: // create an object var ohhai2u = {}; // then do ohhai2u.foo = ‘bar’; // ohhai2u now looks like this {foo: ‘bar’}
  • 14. Inheritance Prototypical Inheritance Class free Objects inherit from other objects An object contains only what makes it different from inherited objects.
  • 15. JS: Sweetness JavaScript is Sandboxed Client Side Data Transport (JSON vs XML) UI Manipulation … DOM!
  • 16. What is the DOM? DOM == Document Object Model The DOM is hierarchical <html> <head> <title>Example JS Page</title> </head> <body> <form id=“some_form”> <input type=“text” name=“bork”/> <input type=“submit” value=“Go”/> </form> </body> </html>
  • 17. Finding DOM Elements document.getElementById() returns a specific element document.getElementByTag() returns an array of elements
  • 18. DOM Element Attributes nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument 1 = an HTML element 2 = an element attribute 3 = text 8 = an HTML comment 9 = a document 10 = a document type definition DOM Attributes Node Types Here’s a good article that uses these.
  • 19. Manipulating the DOM Dynamically creating and adding elements document.createElement appendChild example
  • 20. innerHTML Why go through the trouble of creating Nodes? More efficient Easier example
  • 21. Events Click Dblclick Mousedown Mouseup Mouseover Mousemove Mouseout Keypress Keydown Keyup Select Change Submit Reset Focus Blur Load Unload Abort Error Resize Scroll Mouse Keyboard Frame/Object Form
  • 22. JS: Usage Drop this puppy in your page: <html> <head> <title>Example JS Page</title> <script type=“text/javascript”> // javascript code goes here </script> </head> <body> … </body> </html>
  • 23. Simple Alert Box <html> <head> <title>Example Message Box Page</title> <script type=“text/javascript”> alert(‘I like butter’); </script> </head> <body> … </body> </html>
  • 24. Confirm Box Bound to an Event <html> <head> <title>Example Message Box Page</title> <script type=&quot;text/javascript&quot;> function doLoad() { document.getElementById('sweet-link').addEventListener(‘click’, confirmClick, false); }//end doLoad function confirmClick() { return confirm(‘Are you sure you wish to go to that link?’); }//end confirmClick window.addEventListener(‘load’, doLoad, false); </script> </head> <body> <a id=&quot;sweet-link&quot; href=&quot;http://borkweb.com&quot;>BorkWeb</a> </body> </html> example
  • 25. Hiding/Displaying Elements Element visibility is a nice use of events and DOM manipulation example
  • 26. AJAX AJAX (Asychronous Javascript and XML) Gives you the ability to load content dynamically ! Loading content on demand Possible usability Issues Possible performance problems and benefits Limitation : No AJAX calls beyond the sandbox. Note: The way around this is with XSS (Cross Site Scripting)…which can be dangerous if done poorly.
  • 27. Ajax: XMLHttpRequest Loading content on demand: <script type=&quot;text/javascript&quot;> function ajax(url, vars, callbackFunction){ var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject(&quot;MSXML2.XMLHTTP.3.0&quot;); request.open(&quot;GET&quot;, url, true); request.setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;); request.onreadystatechange = function(){ if (request.readyState == 4 && request.status == 200){ if (request.responseText){ callbackFunction(request.responseText); } } }; request.send(vars); }//end ajax function out(text){ document.getElementById('content').innerHTML = text; }//end out function ajaxCall(){ ajax('http://borkweb.com/examples/js_workshop/dynamic_content1.html','',out);return false; }//end ajaxCall function doLoad(){ document.getElementById('sweet-link').addEventListener('click', ajaxCall, false); }//doLoad window.addEventListener('load', doLoad, false); </script> example
  • 28. WAIT!!!!!!!!!!!!! Things can actually be a bit easier. How much? Well most of the above.
  • 29. WTF? jQuery. That’s what we use on campus. It is awesome.
  • 30. What is jQuery? jQuery is a sweet JavaScript Library Its Mantra: Find stuff and do stuff with it Focuses on simplicity Get it here Check out the docs
  • 31. Finding Elements Say goodbye to document.getElementById() and document.getElementByTag() Say hello to: $() Uses CSS Selectors to find elements and returns them as an array of elements.
  • 32. Finding Elements With $ $(‘a’) $(‘.class’) $(‘#id’) $(‘.content div’) $(‘input[name=bork]’) $(‘input:first’) Here’s an example . Check out the selector syntax for more info.
  • 33. Lets do some of the stuff we already did… Adding Text Fields Toggling Element Visibility Ajax Content
  • 34. jQuery Coolness Browser data $.browser Effects Sliding Fading Animating Chaining $(‘a’).click(function(){alert(‘hello’); return false;}).css(‘font-weight’,’bold’).fadeOut(‘slow’);
  • 35. jQuery Plugins Pluggable! Additional jQuery functionality added by including jQuery plugins .
  • 36. jQuery in myPlymouth Go Sidebar Bookmarks Tab Stack Etc… Check out the source .
  • 37. Before We Start! Important tools to have Use Firefox Firebug JS Debugging FTW Web Developer Toolbar (handy) A sexy text editor (not notepad)
  • 38. The End. Resources: JS: The Good Parts , Slide Examples , jQuery , Image Sprites , Mega Man !

Editor's Notes

  • #4: Javascript isn’t held in very good esteem. People don’t feel like they need to learn it before they start using it…because it *looks* familiar. Looks familiar. Works differently. When people try to use it and it doesn’t work as expected, they hate it even more.
  • #5: All valid: JavaScript is forced upon the developer if programming on the web or a platform with embedded JS This is true. The DOM (Document Object Model) sucks. Luckily there are JS libraries that ease that pain. Once again, the fault of the DOM This is hard to avoid, though there are companies – like Google – that are exerting effort to make JS . Well…there are a number of mistakes…but there are good parts too that make it powerful.
  • #9: Global: No linker. All variables get tossed in a global namespace. Reliability and security problems. XSS +: In a strongly typed environment like Java, that’s hunky dory. In a weakly typed environment…well…it isn’t always obvious if you are going to add or concatenate. Semicolon: These aren’t required and JavaScript tries to insert them for you. How? When the compiler runs into an error, it backs up to a line feed and converts it to a semicolon. typeof: A useful tool as it tells what the type of something is. If you ask what the type of an Object is…it says it is an object. If you do the same for a Number, NULL, a Function, etc…Object. Arrays: Arrays are all just hash tables. Keys are turned into strings. This has a performance hit (though it makes things really easy) == and !=: Type coercion. False: Too many bottom values that are confusing and mean different things
  • #10: Luckily there is a === that would answer false to everything.