Bottom Up JavaScript



Bottom Up JavaScript

   Provide a JavaScript development foundation.

   The only 3 things you ever do with JavaScript:
        0.    Load Scripts
        1.    Attach Event Listener
        2.    Get or modify Data
        3.    Update the page

   Extra burdens:
        Unusual Language Features
        Multiple Environments and Languages
        Divergent and Competing Libraries
        Unusual Performance Considerations
        Scattered Resources and Development Tools

©Jupiter IT                                    JavaScriptMVC
Bottom Up JavaScript



What We Will Learn

   We will learn 'OF' just about everything:

   The JavaScript (JS) Language
   The Document Object Model (DOM)
   How JS and the DOM cooperate
   Libraries
   Development Tools
   Resources




©Jupiter IT                                    JavaScriptMVC
Bottom Up JavaScript



What We Will Learn

   We will learn 'OF' just about everything:

   The JavaScript (JS) Language
   The Document Object Model (DOM)
   How JS and the DOM cooperate
   Libraries
   Development Tools
   Resources




©Jupiter IT                                    JavaScriptMVC
Bottom Up JavaScript



JavaScript

   JavaScript is a dynamic, weakly typed, prototype-
   based language with first-class functions.

     JavaScript        !=   Java
     JavaScript        ==   A real programming language
     JavaScript        ==   ECMAScript == Jscript
     JavaScript        !=   Document Object Model

   JavaScript is typically used in browsers to power
   dynamic websites.

     JS code is loaded and ran with script tags:
      <script type='text/javascript'>alert('hi')</script>
      <script type='text/javascript' src='myjs.js'></script>


©Jupiter IT                                            JavaScriptMVC
Bottom Up JavaScript



JavaScript: Dynamic

   Compilation and execution happen together.

   a = function(){ return 'a' };
   b = function(){ return 'b' };
   if(Math.random() < 0.5)
      c = a;
   else
      c = b;
   a() -> 'a'
   b() -> 'b'
   c() -> ???

   Use these techniques to remove boilerplate
   code.

©Jupiter IT                                     JavaScriptMVC
Bottom Up JavaScript



JavaScript: Weakly Typed

   Type associated with value, not variable.

   var a = 1;
   a = “one”;
   a = [1];
   a = {one: 1};

   Use typeof, instanceof, or other duck typing
   techniques to determine type.

   typeof “abc” -> “string”
   typeof 1 -> “number”
   typeof [] -> “object”

©Jupiter IT                                    JavaScriptMVC
Bottom Up JavaScript



JavaScript: Prototype-based

   Prototype looks up inherited and shared properties.
              Animal = function(name) { this.name = name }
              Animal.prototype.toString = function(){
                return this.name+" has multiple cells, diploid blastula."
              }
              Chordate = function(name){ this.name = name; }
              Chordate.prototype = new Animal();
              Chordate.prototype.has_spine = true;
              Mammal = function(name){ this.name = name; }
              Mammal.prototype = new Chordate();
              Mammal.prototype.has_hair = true;

                             has_hair               has_spine
              Chrdate
               Mmml                     Chrdate
                                        Animal                  Animal
                                                                           toString
              Object
                 p           proto      Object
                                           p            proto     p
                 prototype                  prototype              prototype



              Mmml                      Chrdate                 Animal


©Jupiter IT                                                                           JavaScriptMVC
Bottom Up JavaScript



JavaScript: First Class Functions

   Functions are just like objects, except you
   can put a () after them.
   //create
   square1 = new Function(“x”,”return x*x”);
   square2 = function(x){ return x*x};

   mult = function(f1, f2){
     return function(n){                //return
        return f1(n) * f2(n)
      }
   }
   bigF = mult(square1, square2)        //pass
   bigF(2) -> 16;


©Jupiter IT                                  JavaScriptMVC
Bottom Up JavaScript



JavaScript: First Class Functions

   Functions are just like objects, except you
   can put a () after them.
   //create
   square1 = new Function(“x”,”return x*x”);
   square2 = function(x){ return x*x};

   mult = function(f1, f2){
     return function(n){                //return
        return f1(n) * f2(n)
      }
   }
   bigF = mult(square1, square2)        //pass
   bigF(2) -> 16;


©Jupiter IT                                  JavaScriptMVC
Bottom Up JavaScript



JavaScript: Data Types

   Basic data types:
   ●   Undefined       ->   undefined
   ●   Null            ->   null
   ●   Boolean         ->   true, false
   ●   String          ->   “hello”
   ●   Number          ->   2, 0.2
   ●   Object          ->   {name: “value”}
   ●   Function        ->   function(){}
   ●   Array           ->   [1,2,3]
   ●   Date            ->   new Date()
   ●   RegExp          ->   /.*/g, new RegExp(“.*”,”g”)




©Jupiter IT                                        JavaScriptMVC
Bottom Up JavaScript



Document Object Model

   JS Representation of HTML and browser.
   <html>
      <head></head>
      <body>
           <h1>hi</h1>
      </body>
   </html>

   document = {
     documentElement: {
        nodeName: “HTML”
        childNodes: [
          {nodeName: “HEAD”, childNodes: []},
          {
            nodeName : “BODY”
            childNodes: [{nodeName: 'h1', innerHTML: "hi"}]
          }
        ]
     },
     getElementById : function(id){ ... }
   }


©Jupiter IT                                                   JavaScriptMVC
Bottom Up JavaScript



Document Object Model

   JS Representation of HTML and browser.
   Browser
       navigator.userAgent
   Page
        location
   Document
        var el=document.getElementById('eid')
   Ajax
       new XMLHttpRequest()
   Events
       el.attachEventListener('click',f,false)
   Elements
       el.style.backgroundColor = “blue”         Source: Wikipedia


©Jupiter IT                                           JavaScriptMVC
Bottom Up JavaScript



Three Things

   1. Respond to an event
   Find Element -> Document / Element
   Attach Event Listener -> Element
           ...
   2. Get or Modify Data
           ...
   From Server -> XMLHttpRequest / Ajax
   From HTML -> Document / Element
   From Location -> Location
               ...
   3. Update the Page
               ...
   Change Element -> Element
   Change Location -> Location




©Jupiter IT                               JavaScriptMVC
Bottom Up JavaScript



Three Things
   Use the DOM for each part, stitch it together with JS.

   <a id='find_price'>Find Price</a>
   <div id='price'></div>


   1. Attach Event Listener
   var el = FindElement('find_price')
   el.AttachFunctionToRunOn('click',getAndSetPrice)

   2. Get or Modify Data
   function getAndSetPrice(){
      price = GetDataFrom('/getPrice')
      ...
   3. Update the Page
       ...
       var pel = FindElement('price')
       pel.InsertText(price)
   }

©Jupiter IT                                           JavaScriptMVC
Bottom Up JavaScript



Three Things
   <a id='find_price'>Find Price</a>
   <div id='price'></div>

   1. Attach Event Listener
   var el=document.getElementById('find_price')       //FindElement
   el.attachEventListener('click', getAndSetPrice, false); //attach

   2. Get or Modify Data
   getAndSetPrice = function(event){
      var xhr = new XMLHttpRequest()       //GetDataFrom
      xhr.open("GET", "/getPrice", false); //don't do this!
      xhr.send();
      var price = xhr.responseText;
      ...
   3. Update the Page
       ...
       document.getElementById('price').innerHTML = price;
   }

©Jupiter IT                                            JavaScriptMVC
Bottom Up JavaScript



Libraries

   Exist to make things easier:
   Browser inconsistencies
       attachEvent vs addEventListener
       XMLHttpRequest vs ActiveXObject

   DOM API weaknesses
       $('#sidebar .ul').height()
       document.getElementById('sidebar').
           childNodes[2].offsetHeight

   Common tasks
       Drag/drop, AutoComplete, Slider, Sortable Tables

   Language improvements
       [].each(), “isRed”.startsWith(“is”)

   Do you need a library -> YES!!!
©Jupiter IT                                               JavaScriptMVC
Bottom Up JavaScript



Library Selection




©Jupiter IT            JavaScriptMVC
Bottom Up JavaScript



Tools

   Debugging
       Firebug (FF)
       MS Visual Web Developer (IE)
       DragonFly (Opera)
       Chrome
       Drosera / Web Inspector (Safari)

   Compression
       Dojo Shrink Safe
       YUI
       Dean Edwards Packer / Compress.js

   Performance
        Yslow
        Firebug
        Chrome's development tools




©Jupiter IT                                JavaScriptMVC
Bottom Up JavaScript



Tools Continued ...

   Testing
       In browser (easy) - JSUnit
       Browser Control (comprehensive) - Selenium
       Simulated (fast) – Env.js

   Documentation
      JSDoc – Understands JavaScript, hard to document complex
   features
      Natural Docs – Can document anything
      MVCDoc – Can document anything, understands some JS.




©Jupiter IT                                           JavaScriptMVC
Bottom Up JavaScript



Resources

   Documentation
       Mozilla Development Center
       MSDN Internet Explorer Development Center
       Quirksmode

   Books
       JavaScript - the Definitive Guide. David Flanagan
       JavaScript – the Good Parts. Douglas Crockford

   News
       Ajaxian
       Ejohn.org




©Jupiter IT                                            JavaScriptMVC
Bottom Up JavaScript



Three Things Revisited

   0.         Load Script
   <!-- Use a compressor to load a single script. -->
   <script type='text/javascript' src='production.js'></script>

   1. Respond to an event
   //Attach event handlers when you know the document is ready
   $(function(){
       $(“#find_price”).click(function(event){
           ...
   2. Get or Modify Data
               ...
               $.get('/getPrice',function(price){
                   ...
   3. Update the Page
                     ...
                     $(“#price”).text(price);
               });
   })


©Jupiter IT                                           JavaScriptMVC
Bottom Up JavaScript



Three Things Revisited Cont...
   MyCo.updatePrice = function(price){
     $(“#price”).text(price);
   }
   MyCo.getAndUpdatePrice = function(){
      $.get('/getPrice',MyCo.updatePrice)
   }
   $(function(){
      $(“#find_price”).click(MyCo.getAndUpdatePrice)
   })
   OR Maybe ...
   $.Controller.extend('MyCo.Controllers.FindPrice',{
     click : function(){
       MyCo.Price.get(this.callback('updatePrice'))
     },
     updatePrice : function(price){
       $(“#price).html({view: 'price',data: {price: price});
     }
   })
   <!-- in views/find_price/price.ejs -->
   Your price is <span class='highlight'><%= price %></span>

©Jupiter IT                                            JavaScriptMVC
Bottom Up JavaScript



What we've learned

   The JavaScript (JS) Language
   The Document Object Model (DOM)
   How JS and the DOM cooperate
   Libraries
   Development Tools
   Resources




©Jupiter IT                          JavaScriptMVC

More Related Content

PDF
Headless Js Testing
PDF
Singletons in PHP - Why they are bad and how you can eliminate them from your...
PDF
Design Patterns Reconsidered
PDF
Anonymous functions in JavaScript
PDF
Min-Maxing Software Costs
PDF
PHPSpec - the only Design Tool you need - 4Developers
PPTX
Clean Code Development
PDF
Design Patterns in PHP5
Headless Js Testing
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Design Patterns Reconsidered
Anonymous functions in JavaScript
Min-Maxing Software Costs
PHPSpec - the only Design Tool you need - 4Developers
Clean Code Development
Design Patterns in PHP5

What's hot (20)

PDF
A Re-Introduction to JavaScript
PDF
Object Oriented JavaScript
PDF
Clean code in JavaScript
PDF
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
PDF
Decoupling with Design Patterns and Symfony2 DIC
PDF
Rich Model And Layered Architecture in SF2 Application
PDF
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PDF
Impact of the New ORM on Your Modules
PPT
Система рендеринга в Magento
PPTX
Crafting beautiful software
PDF
Writing clean code
PDF
The IoC Hydra
PDF
The IoC Hydra - Dutch PHP Conference 2016
PPT
Javascript Experiment
PDF
PhpSpec 2.0 ilustrated by examples
ZIP
Lisp Macros in 20 Minutes (Featuring Clojure)
PPT
Java script -23jan2015
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
PDF
06 jQuery #burningkeyboards
PDF
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
A Re-Introduction to JavaScript
Object Oriented JavaScript
Clean code in JavaScript
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Decoupling with Design Patterns and Symfony2 DIC
Rich Model And Layered Architecture in SF2 Application
PHPCon 2016: PHP7 by Witek Adamus / XSolve
Impact of the New ORM on Your Modules
Система рендеринга в Magento
Crafting beautiful software
Writing clean code
The IoC Hydra
The IoC Hydra - Dutch PHP Conference 2016
Javascript Experiment
PhpSpec 2.0 ilustrated by examples
Lisp Macros in 20 Minutes (Featuring Clojure)
Java script -23jan2015
international PHP2011_Bastian Feder_jQuery's Secrets
06 jQuery #burningkeyboards
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Ad

Similar to Bottom Up (20)

PPT
eXo SEA - JavaScript Introduction Training
PPT
JavaScript Misunderstood
PPTX
Lab #2: Introduction to Javascript
PPT
Java Script ppt
PDF
Secrets of JavaScript Libraries
PPTX
introduction to java scriptsfor sym.pptx
PPT
Introduction to Javascript
PDF
JavaScript Core
PPTX
Oojs 1.1
PPTX
Adding a modern twist to legacy web applications
PPTX
Adding a modern twist to legacy web applications
PPT
Javascript quiz. Questions to ask when recruiting developers.
PDF
Javascript Frameworks for Joomla
PPTX
Java scriptforjavadev part2a
PPTX
IWT presentation121232112122222225556+556.pptx
PPT
JavaScript Basics
PDF
droidQuery: The Android port of jQuery
PDF
What's new in DWR version 3
PPTX
J Query The Write Less Do More Javascript Library
eXo SEA - JavaScript Introduction Training
JavaScript Misunderstood
Lab #2: Introduction to Javascript
Java Script ppt
Secrets of JavaScript Libraries
introduction to java scriptsfor sym.pptx
Introduction to Javascript
JavaScript Core
Oojs 1.1
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Javascript quiz. Questions to ask when recruiting developers.
Javascript Frameworks for Joomla
Java scriptforjavadev part2a
IWT presentation121232112122222225556+556.pptx
JavaScript Basics
droidQuery: The Android port of jQuery
What's new in DWR version 3
J Query The Write Less Do More Javascript Library
Ad

More from Brian Moschel (11)

KEY
A Very Biased Comparison of MVC Libraries
PPTX
FuncUnit
PPTX
Comet: an Overview and a New Solution Called Jabbify
PDF
Web 2.0 Expo Notes
PDF
Comet, Simplified, with Jabbify Comet Service
PDF
Building an App with jQuery and JAXER
PPT
JavaScript Functions
ODP
ODP
Basic inheritance in JavaScript
PDF
Things to avoid in JavaScript
PDF
Javascript and DOM
A Very Biased Comparison of MVC Libraries
FuncUnit
Comet: an Overview and a New Solution Called Jabbify
Web 2.0 Expo Notes
Comet, Simplified, with Jabbify Comet Service
Building an App with jQuery and JAXER
JavaScript Functions
Basic inheritance in JavaScript
Things to avoid in JavaScript
Javascript and DOM

Recently uploaded (20)

PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
Chapter 5: Probability Theory and Statistics
PDF
August Patch Tuesday
PDF
Unlock new opportunities with location data.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
The various Industrial Revolutions .pptx
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
DOCX
search engine optimization ppt fir known well about this
PPTX
Tartificialntelligence_presentation.pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Group 1 Presentation -Planning and Decision Making .pptx
O2C Customer Invoices to Receipt V15A.pptx
Zenith AI: Advanced Artificial Intelligence
A novel scalable deep ensemble learning framework for big data classification...
Chapter 5: Probability Theory and Statistics
August Patch Tuesday
Unlock new opportunities with location data.pdf
A comparative study of natural language inference in Swahili using monolingua...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
The various Industrial Revolutions .pptx
Web Crawler for Trend Tracking Gen Z Insights.pptx
search engine optimization ppt fir known well about this
Tartificialntelligence_presentation.pptx
Getting started with AI Agents and Multi-Agent Systems
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Module 1.ppt Iot fundamentals and Architecture
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf

Bottom Up

  • 1. Bottom Up JavaScript Bottom Up JavaScript Provide a JavaScript development foundation. The only 3 things you ever do with JavaScript: 0. Load Scripts 1. Attach Event Listener 2. Get or modify Data 3. Update the page Extra burdens: Unusual Language Features Multiple Environments and Languages Divergent and Competing Libraries Unusual Performance Considerations Scattered Resources and Development Tools ©Jupiter IT JavaScriptMVC
  • 2. Bottom Up JavaScript What We Will Learn We will learn 'OF' just about everything: The JavaScript (JS) Language The Document Object Model (DOM) How JS and the DOM cooperate Libraries Development Tools Resources ©Jupiter IT JavaScriptMVC
  • 3. Bottom Up JavaScript What We Will Learn We will learn 'OF' just about everything: The JavaScript (JS) Language The Document Object Model (DOM) How JS and the DOM cooperate Libraries Development Tools Resources ©Jupiter IT JavaScriptMVC
  • 4. Bottom Up JavaScript JavaScript JavaScript is a dynamic, weakly typed, prototype- based language with first-class functions. JavaScript != Java JavaScript == A real programming language JavaScript == ECMAScript == Jscript JavaScript != Document Object Model JavaScript is typically used in browsers to power dynamic websites. JS code is loaded and ran with script tags: <script type='text/javascript'>alert('hi')</script> <script type='text/javascript' src='myjs.js'></script> ©Jupiter IT JavaScriptMVC
  • 5. Bottom Up JavaScript JavaScript: Dynamic Compilation and execution happen together. a = function(){ return 'a' }; b = function(){ return 'b' }; if(Math.random() < 0.5) c = a; else c = b; a() -> 'a' b() -> 'b' c() -> ??? Use these techniques to remove boilerplate code. ©Jupiter IT JavaScriptMVC
  • 6. Bottom Up JavaScript JavaScript: Weakly Typed Type associated with value, not variable. var a = 1; a = “one”; a = [1]; a = {one: 1}; Use typeof, instanceof, or other duck typing techniques to determine type. typeof “abc” -> “string” typeof 1 -> “number” typeof [] -> “object” ©Jupiter IT JavaScriptMVC
  • 7. Bottom Up JavaScript JavaScript: Prototype-based Prototype looks up inherited and shared properties. Animal = function(name) { this.name = name } Animal.prototype.toString = function(){ return this.name+" has multiple cells, diploid blastula." } Chordate = function(name){ this.name = name; } Chordate.prototype = new Animal(); Chordate.prototype.has_spine = true; Mammal = function(name){ this.name = name; } Mammal.prototype = new Chordate(); Mammal.prototype.has_hair = true; has_hair has_spine Chrdate Mmml Chrdate Animal Animal toString Object p proto Object p proto p prototype prototype prototype Mmml Chrdate Animal ©Jupiter IT JavaScriptMVC
  • 8. Bottom Up JavaScript JavaScript: First Class Functions Functions are just like objects, except you can put a () after them. //create square1 = new Function(“x”,”return x*x”); square2 = function(x){ return x*x}; mult = function(f1, f2){ return function(n){ //return return f1(n) * f2(n) } } bigF = mult(square1, square2) //pass bigF(2) -> 16; ©Jupiter IT JavaScriptMVC
  • 9. Bottom Up JavaScript JavaScript: First Class Functions Functions are just like objects, except you can put a () after them. //create square1 = new Function(“x”,”return x*x”); square2 = function(x){ return x*x}; mult = function(f1, f2){ return function(n){ //return return f1(n) * f2(n) } } bigF = mult(square1, square2) //pass bigF(2) -> 16; ©Jupiter IT JavaScriptMVC
  • 10. Bottom Up JavaScript JavaScript: Data Types Basic data types: ● Undefined -> undefined ● Null -> null ● Boolean -> true, false ● String -> “hello” ● Number -> 2, 0.2 ● Object -> {name: “value”} ● Function -> function(){} ● Array -> [1,2,3] ● Date -> new Date() ● RegExp -> /.*/g, new RegExp(“.*”,”g”) ©Jupiter IT JavaScriptMVC
  • 11. Bottom Up JavaScript Document Object Model JS Representation of HTML and browser. <html> <head></head> <body> <h1>hi</h1> </body> </html> document = { documentElement: { nodeName: “HTML” childNodes: [ {nodeName: “HEAD”, childNodes: []}, { nodeName : “BODY” childNodes: [{nodeName: 'h1', innerHTML: "hi"}] } ] }, getElementById : function(id){ ... } } ©Jupiter IT JavaScriptMVC
  • 12. Bottom Up JavaScript Document Object Model JS Representation of HTML and browser. Browser navigator.userAgent Page location Document var el=document.getElementById('eid') Ajax new XMLHttpRequest() Events el.attachEventListener('click',f,false) Elements el.style.backgroundColor = “blue” Source: Wikipedia ©Jupiter IT JavaScriptMVC
  • 13. Bottom Up JavaScript Three Things 1. Respond to an event Find Element -> Document / Element Attach Event Listener -> Element ... 2. Get or Modify Data ... From Server -> XMLHttpRequest / Ajax From HTML -> Document / Element From Location -> Location ... 3. Update the Page ... Change Element -> Element Change Location -> Location ©Jupiter IT JavaScriptMVC
  • 14. Bottom Up JavaScript Three Things Use the DOM for each part, stitch it together with JS. <a id='find_price'>Find Price</a> <div id='price'></div> 1. Attach Event Listener var el = FindElement('find_price') el.AttachFunctionToRunOn('click',getAndSetPrice) 2. Get or Modify Data function getAndSetPrice(){ price = GetDataFrom('/getPrice') ... 3. Update the Page ... var pel = FindElement('price') pel.InsertText(price) } ©Jupiter IT JavaScriptMVC
  • 15. Bottom Up JavaScript Three Things <a id='find_price'>Find Price</a> <div id='price'></div> 1. Attach Event Listener var el=document.getElementById('find_price') //FindElement el.attachEventListener('click', getAndSetPrice, false); //attach 2. Get or Modify Data getAndSetPrice = function(event){ var xhr = new XMLHttpRequest() //GetDataFrom xhr.open("GET", "/getPrice", false); //don't do this! xhr.send(); var price = xhr.responseText; ... 3. Update the Page ... document.getElementById('price').innerHTML = price; } ©Jupiter IT JavaScriptMVC
  • 16. Bottom Up JavaScript Libraries Exist to make things easier: Browser inconsistencies attachEvent vs addEventListener XMLHttpRequest vs ActiveXObject DOM API weaknesses $('#sidebar .ul').height() document.getElementById('sidebar'). childNodes[2].offsetHeight Common tasks Drag/drop, AutoComplete, Slider, Sortable Tables Language improvements [].each(), “isRed”.startsWith(“is”) Do you need a library -> YES!!! ©Jupiter IT JavaScriptMVC
  • 17. Bottom Up JavaScript Library Selection ©Jupiter IT JavaScriptMVC
  • 18. Bottom Up JavaScript Tools Debugging Firebug (FF) MS Visual Web Developer (IE) DragonFly (Opera) Chrome Drosera / Web Inspector (Safari) Compression Dojo Shrink Safe YUI Dean Edwards Packer / Compress.js Performance Yslow Firebug Chrome's development tools ©Jupiter IT JavaScriptMVC
  • 19. Bottom Up JavaScript Tools Continued ... Testing In browser (easy) - JSUnit Browser Control (comprehensive) - Selenium Simulated (fast) – Env.js Documentation JSDoc – Understands JavaScript, hard to document complex features Natural Docs – Can document anything MVCDoc – Can document anything, understands some JS. ©Jupiter IT JavaScriptMVC
  • 20. Bottom Up JavaScript Resources Documentation Mozilla Development Center MSDN Internet Explorer Development Center Quirksmode Books JavaScript - the Definitive Guide. David Flanagan JavaScript – the Good Parts. Douglas Crockford News Ajaxian Ejohn.org ©Jupiter IT JavaScriptMVC
  • 21. Bottom Up JavaScript Three Things Revisited 0. Load Script <!-- Use a compressor to load a single script. --> <script type='text/javascript' src='production.js'></script> 1. Respond to an event //Attach event handlers when you know the document is ready $(function(){ $(“#find_price”).click(function(event){ ... 2. Get or Modify Data ... $.get('/getPrice',function(price){ ... 3. Update the Page ... $(“#price”).text(price); }); }) ©Jupiter IT JavaScriptMVC
  • 22. Bottom Up JavaScript Three Things Revisited Cont... MyCo.updatePrice = function(price){ $(“#price”).text(price); } MyCo.getAndUpdatePrice = function(){ $.get('/getPrice',MyCo.updatePrice) } $(function(){ $(“#find_price”).click(MyCo.getAndUpdatePrice) }) OR Maybe ... $.Controller.extend('MyCo.Controllers.FindPrice',{ click : function(){ MyCo.Price.get(this.callback('updatePrice')) }, updatePrice : function(price){ $(“#price).html({view: 'price',data: {price: price}); } }) <!-- in views/find_price/price.ejs --> Your price is <span class='highlight'><%= price %></span> ©Jupiter IT JavaScriptMVC
  • 23. Bottom Up JavaScript What we've learned The JavaScript (JS) Language The Document Object Model (DOM) How JS and the DOM cooperate Libraries Development Tools Resources ©Jupiter IT JavaScriptMVC