SlideShare une entreprise Scribd logo
1  sur  63
Télécharger pour lire hors ligne
taken by Jeremy Keith - http://www.flickr.com/photos/adactio/

                      Writing jQuery JavaScript that doesn’t suck
Monday, 4 July 2011
Introductions




                      Ross Bruniges
Monday, 4 July 2011
Introductions




                                 taken by Mike Morgan - http://www.flickr.com/photos/morgamic/

                      Ross Bruniges, Web Developer at Mozilla
Monday, 4 July 2011
Introductions




                      careers.mozilla.com



                            We’re hiring!
Monday, 4 July 2011
Introductions




                                     taken by Mike Morgan - http://www.flickr.com/photos/morgamic/

                      Ross Bruniges, Regular drinker at Pub Standards
Monday, 4 July 2011
Introductions




                               taken by Caz Mockett - http://www.flickr.com/photos/rugbymadgirl/

                      So what am I going to be talking about?
Monday, 4 July 2011
Introductions




                        taken by Julian Burgess - http://www.flickr.com/photos/aubergene/

                      A JavaScript mixed bag.
Monday, 4 July 2011
Organisation




                      Leaving things as you would like them to be found
Monday, 4 July 2011
Organisation




     JSLint is a JavaScript program that looks for
     problems in JavaScript programs. It is a code
     quality tool.




                             More information on the JS Lint at http://www.jslint.com/lint.html

                      Remember to useJavaScript
                           Lint your eventDelegation
Monday, 4 July 2011
Organisation


     application = some large JS app (global)


     function eatMe() {
              // accessing the global variable
              application = false;
     }


     eatMe();


     application.shouldWork();// now returns false


                      Beware Remember to use eventDelegation
                             global variables, they are easy to overwrite
Monday, 4 July 2011
Organisation


     application = some large JS app (global)


     function eatMe() {
              // now accessing a local variable
                 var       application = false;
     }


     eatMe();


     application.shouldWork()// now works


                      Beware Remember to use eventDelegation
                             global variables, they are easy to overwrite
Monday, 4 July 2011
Organisation




     return
     {
       javascript : "fantastic"
     };




                                                        Example by Douglas Crockford

                      Don’t rely on semi-colon insertion to work
                         Remember to use eventDelegation
Monday, 4 July 2011
Organisation




     return; // Semicolon inserted, believing the
     statement has finished. Returns undefined
     { // Considered to be an anonymous block, doing
     nothing
       javascript : "fantastic"
     };// Semicolon interpreted as an empty dummy line
     and moved down




                                                        Example by Douglas Crockford

                      Don’t rely on semi-colon insertion to work
                         Remember to use eventDelegation
Monday, 4 July 2011
Organisation




     return {
       javascript : "fantastic"
     };




                                                  Example by Douglas Crockford

        Hug your brackets and remember to include your semi-colons
                    Remember to use eventDelegation
Monday, 4 July 2011
Organisation




     1 == true // returns true as 1 is a ‘truthy’
     value and gets converted to such


     1 === true // returns false as no conversion is
     applied




                      Remember to use eventDelegation
                          Always use === and !==
Monday, 4 July 2011
Organisation




                                      More Crockford facts at http://crockfordfacts.com/

                      Remember to for Douglas
                            Do it use eventDelegation
Monday, 4 July 2011
Organisation




     $(‘#foo’).click(function(){console.log(‘please
     stop this madness’);}).end().filter
     (‘div.urgghhh’)


     Pain for someone down the line




  Avoid long chained statements use eventDelegation doesn’t mean
                  Remember to - just because you can
                           that you should.
Monday, 4 July 2011
Organisation




                      Remember to likes eventDelegation
                         Everyone use a nice chain
Monday, 4 July 2011
Organisation




         But you can end up looking use eventDelegationget too much
                      Remember to like a douche if you
Monday, 4 July 2011
Organisation




     $(‘#foo’)
           .click(function(){
                 console.log(‘please stop this madness’);
           })
           .end()
           .filter(‘div.urgghhh’);




                        Remember to use eventDelegation
                             This works just fine
Monday, 4 July 2011
Organisation




                      Remember of a JS Design Pattern
                       Make use to use eventDelegation
Monday, 4 July 2011
Organisation




                                    http://addyosmani.com/blog/essentialjsdesignpatterns/

                      Remember to use eventDelegation
                               Free book!
Monday, 4 July 2011
Organisation

     var clean = function() {
                 var debug = false;
                 var init = function() {
                      console.log(‘fail’);
                 };
                 return {
                      init : init
                 };
     }();


     clean.init();


         Revealing Module Pattern - clean, tidy and easy to understand
                     Remember to use eventDelegation
Monday, 4 July 2011
Organisation




                      Remember to well eventDelegation
                       Modules play use with JS loaders
Monday, 4 July 2011
Organisation




                      Remember over complication
                          Avoid to use eventDelegation
Monday, 4 July 2011
Organisation




      Just because you THINK it to use be cool doesn’t mean it will be.
                     Remember might eventDelegation
                    Especially if no one has asked for it.
Monday, 4 July 2011
Organisation



     function poorlyThoughtOut() {
        // OK I’m going to get some elements
        // add a class or two
        // parse some data from the elements
        // remove some DOM elements
        // parse some data from someplace else
        // fade the background to yellow to highlight
     the change
        // update the screenreader buffer
     }




                      Don’t stuff your functions until they burst
                        Remember to use eventDelegation
Monday, 4 July 2011
Organisation


     function parseData() {}

     function updateBuffer() {}

     function betterPlanned() {
        // OK I’m going to get some elements
        // add a class or two
        // parseData()
        // remove some DOM elements
        // parseData()
        // updateBuffer()
     }



         Smaller functions are easier useunderstand and more modular
                       Remember to to eventDelegation
Monday, 4 July 2011
Organisation


     In your code trigger an event
     $.trigger(‘carousel_move’);


     If someone needs it they can use it later
     $.bind(‘carousel_move’, function(e) {
       console.log(‘event functionality without
     needing to alter the existing code base’);
     });




                      Custom events to to use for future development
                           Remember allow eventDelegation
Monday, 4 July 2011
Organisation

     //
     // Dear maintainer:
     //
     // Once you are done trying to 'optimize' this
     routine,
     // and have realized what a terrible mistake that
     was,
     // please increment the following counter as a
     warning
     // to the next guy:
     //
     // total_hours_wasted_here = 39
     //

                      comment from stackoverflow thread - http://stackoverflow.com/questions/184618/

                         Remember to useyour code
                              Comment eventDelegation
Monday, 4 July 2011
Organisation



    /**
      * Change the role of the employee.
      * @param {integer} employeeId The id of the
    employee.
      * @param {string} [newRole] The new role of the
    employee.
      */
    function recast(employeeId, newRole) {
    }




                                      project homepage at http://code.google.com/p/jsdoc-toolkit/

                      JSDocToolkit - commentseventDelegation out
                            Remember to use in, documentation
Monday, 4 July 2011
Organisation


     /*
     @name vehicle.Sled#reindeer
     @function
     @description Set the reindeer that will pull
     Santa's sled.
     @param {string[]} reindeer A list of the
     reindeer.
     @example
     // specifying some reindeer
     Sled().reindeer(['Dasher', 'Dancer', 'Rudolph',
     'Vixen']);
     */


              full article by Frances Berriman at http://24ways.org/2010/documentation-driven-design-for-apis

           Documentation-Driven Design,eventDelegationcode second
                     Remember to use document first
Monday, 4 July 2011
Organisation




                       // TODO: Fix this.                 Fix what?




                        comment from stackoverflow thread - http://stackoverflow.com/questions/184618/

                  WhateverRemember to use eventDelegation the start.
                           you choose ensure you do it from
Monday, 4 July 2011
Organisation




                      /**
                        * Always returns true.
                        */
                      public boolean isAvailable() {
                           return false;
                      }




                      comment from stackoverflow thread - http://stackoverflow.com/questions/184618/

                         Remember to it upeventDelegation
                               Keep use to date
Monday, 4 July 2011
Performance




                      diagram from http://www.sapdesignguild.org/



Monday, 4 July 2011
Performance




                                     taken by pi.kappa - http://www.flickr.com/photos/27890120@N08/

                      Don’t prematurely optimise - you’re just ASSuming
Monday, 4 July 2011
Performance



     $(‘#foo div’) = bad, it will search first for ALL
     divs in the document;

     $(‘div.me’) is better it will only search for
     divs with that specific class

     $(‘div#me’) = best, all JS parses will look only
     for that specific element




          Write good selectors (sizzle parse right to left - in IE6 and 7)
Monday, 4 July 2011
Performance




     var expensive-selector = $(“.section:first”),
         reused-json-object = $.getJSON(‘docs.json’),
         reusable-regex = /d(b+)d/g;




                      Cache quicker for reuse
Monday, 4 July 2011
Performance




                      Exit quickly to avoid silent fails
Monday, 4 July 2011
Performance




     var elm = $(‘#findMe’);

     if (!elm.length) { return false; }

     We now know that this code will only be run if
     the element actually exists.




                      Exit quickly to avoid silent fails
Monday, 4 July 2011
Performance




        from The Mysteries of JavaScript Fu, Dan Webb - http://www.slideshare.net/danwrong/java-script-fu-

                            Remember to use eventDelegation
Monday, 4 July 2011
Performance



     .live() example - quick and dirty

     $('tr').live('click', function(event) {
         // this == tr element
     });




                      Code examples from http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery

                                 Remember to use eventDelegation
Monday, 4 July 2011
Performance



     .delegate() example - also chainable

     $('table').delegate('tr', 'click', function(event){
         // this == tr element
     });




                      Code examples from http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery

                                 Remember to use eventDelegation
Monday, 4 July 2011
Performance



     Handrolled example - maximum control

     $('table').bind('click', function(event) {
         // this == table element
         var $tr = $(event.target).closest('tr');
     });




                      Code examples from http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery

                                 Remember to use eventDelegation
Monday, 4 July 2011
Performance




                      Cause minimal reflows use eventDelegation in IE)
                             Remember to and repaints (especially
Monday, 4 July 2011
Performance




     “Repaint - also known as redraw - is what happens
     whenever something is made visible when it was
     not previously visible, or vice versa, without
     altering the layout of the document.”




                        Quote from http://dev.opera.com/articles/view/efficient-javascript/?page=all

                      Remember to use eventDelegation
                                Repaints
Monday, 4 July 2011
Performance



     “whenever the DOM tree is manipulated, whenever a
     style is changed that affects the layout,
     whenever the className property of an element is
     changed, or whenever the browser window size is
     changed...


     In many cases, they are equivalent to laying out
     the entire page again.”




                        Quote from http://dev.opera.com/articles/view/efficient-javascript/?page=all

                      Remember toReflows
                                  use eventDelegation
Monday, 4 July 2011
Performance




                      Remember to use eventDelegation
                       Use the latest version of jQuery!
Monday, 4 July 2011
Don’t forget your accessibility




                            taken by Drew McLellan - http://www.flickr.com/photos/drewm/



Monday, 4 July 2011
Don’t forget your accessibility




                      Don’t forget your focus (and blur)
Monday, 4 July 2011
Don’t forget your accessibility




     $(‘#foo’).bind(‘mouseenter focus’, function(e) {
        code goes here
     });

     $(‘#foo’).bind(‘mouseleave blur’, function(e) {
        code goes here
     });




   If you use .bind (opposed to .click) you can include multiple events
Monday, 4 July 2011
Don’t forget your accessibility




      Invalid mark-up is still invalid mark-up even when inserted via JS
Monday, 4 July 2011
Don’t forget your accessibility




                      Remember to update the screenreader buffer
Monday, 4 July 2011
Don’t forget your accessibility




     1. Update the value of a hidden input field
     2. Ensure that you have a tabIndex value of -1 on
     the element that you’ve altered
     3. .focus() on the newly inserted content




                           The old(ish) way
Monday, 4 July 2011
Don’t forget your accessibility




     “Live region markup allows web page authors to
     specify when and how live changes to specific
     areas of a web page should be spoken or shown on
     a Braille display by a screen reader.”




                      Read more at https://developer.mozilla.org/en/AJAX/WAI_ARIA_Live_Regions

                      The new(ish) way - ARIA live regions
Monday, 4 July 2011
Don’t forget your accessibility


     aria-live - sets the frequency of updates to AT

     aria-controls - associates a control with an
     area. All actions on that control are announced
     by AT

     aria-relevant - states what changes to the live
     region are to be announced to AT




                      Read more at https://developer.mozilla.org/en/AJAX/WAI_ARIA_Live_Regions

                      The new(ish) way - ARIA live regions
Monday, 4 July 2011
Don’t forget
Performance your ‘edge cases’




Monday, 4 July 2011
Don’t forget your ‘edge cases’




                      If things can goto use eventDelegation
                          Remember wrong then normally will
Monday, 4 July 2011
Don’t forget your ‘edge cases’




     Remember to code for when the server doesn’t return
     a value - it might be down or the app might be
     broken.

     The server might take longer to reply than expected
     and cause a timeout meaning an empty return value.




                      If things can go wrong then normally will
Monday, 4 July 2011
Don’t forget your ‘edge cases’
     $.ajax is the backbone to all jQuery AJAX methods
     like $.getScript or $.getJSON and allows for much
     greater flexibility.

     $.ajax({
       url : “foo.php”,
       dataType : “json”,
       success : function(data) {
          gets sent the JSON response
       },
       error : function() {
          gets sent the error type and text
       },
       timeout : 1000
     });



                      Remember toto the rescue
                           $.ajax use eventDelegation
Monday, 4 July 2011
Don’t forget your ‘edge cases’ - like other browsers!




                      Remember toause eventDelegation
                       jQuery isn’t 100% magic bullet
Monday, 4 July 2011
Thanks for listening!




                      http://bit.ly/ross-london-jquery




                        Remember to use eventDelegation
                             Looking for the links?
Monday, 4 July 2011
Taken by Mark Klotz - http://www.flickr.com/photos/markklotz/

                      Remember toCheers!
                                  use eventDelegation
Monday, 4 July 2011

Contenu connexe

En vedette

Seres Dos CartõEs
Seres Dos CartõEsSeres Dos CartõEs
Seres Dos CartõEsSérgio Luiz
 
Rba impian-guide-sept-20132
Rba impian-guide-sept-20132Rba impian-guide-sept-20132
Rba impian-guide-sept-20132burhan fuady
 
Peterson 1klass2
Peterson 1klass2Peterson 1klass2
Peterson 1klass2qwasar1
 
Cisco 3900 and cisco 2900 series routers
Cisco 3900 and cisco 2900 series routersCisco 3900 and cisco 2900 series routers
Cisco 3900 and cisco 2900 series routers3Anetwork com
 
Đề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh Hóa
Đề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh HóaĐề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh Hóa
Đề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh Hóaschoolantoreecom
 
‘Poder influência’, adverte o procurador
‘Poder influência’, adverte o procurador‘Poder influência’, adverte o procurador
‘Poder influência’, adverte o procuradorRadar News
 
Las leyes naturales, según Thomas Hobbes
Las leyes naturales, según Thomas HobbesLas leyes naturales, según Thomas Hobbes
Las leyes naturales, según Thomas HobbesFede Canut
 
Geography of Bihar by Eithasab Ahmed
Geography of Bihar by Eithasab AhmedGeography of Bihar by Eithasab Ahmed
Geography of Bihar by Eithasab AhmedPonnuru Varun
 
Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516rozeka01
 
44 tushaal
44 tushaal44 tushaal
44 tushaalrtumur
 
Tool room & engineering manager
Tool room & engineering managerTool room & engineering manager
Tool room & engineering managerrislam2008
 

En vedette (20)

Seres Dos CartõEs
Seres Dos CartõEsSeres Dos CartõEs
Seres Dos CartõEs
 
Concumer behavior
Concumer behaviorConcumer behavior
Concumer behavior
 
Groasis Waterboxx - Popular Science Winner of Best of What's New in 2010
Groasis Waterboxx - Popular Science Winner of Best of What's New in 2010Groasis Waterboxx - Popular Science Winner of Best of What's New in 2010
Groasis Waterboxx - Popular Science Winner of Best of What's New in 2010
 
Oppa (30)
Oppa (30)Oppa (30)
Oppa (30)
 
Rba impian-guide-sept-20132
Rba impian-guide-sept-20132Rba impian-guide-sept-20132
Rba impian-guide-sept-20132
 
Backtrack 3 USB
Backtrack 3 USBBacktrack 3 USB
Backtrack 3 USB
 
Excellence land rover
Excellence land roverExcellence land rover
Excellence land rover
 
Peterson 1klass2
Peterson 1klass2Peterson 1klass2
Peterson 1klass2
 
Cisco 3900 and cisco 2900 series routers
Cisco 3900 and cisco 2900 series routersCisco 3900 and cisco 2900 series routers
Cisco 3900 and cisco 2900 series routers
 
posititude - Dec 14
posititude - Dec 14posititude - Dec 14
posititude - Dec 14
 
Đề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh Hóa
Đề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh HóaĐề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh Hóa
Đề thi thử Đại học lần 1 năm 2016 THPT Bỉm Sơn Thanh Hóa
 
Break Through
Break ThroughBreak Through
Break Through
 
‘Poder influência’, adverte o procurador
‘Poder influência’, adverte o procurador‘Poder influência’, adverte o procurador
‘Poder influência’, adverte o procurador
 
Las leyes naturales, según Thomas Hobbes
Las leyes naturales, según Thomas HobbesLas leyes naturales, según Thomas Hobbes
Las leyes naturales, según Thomas Hobbes
 
Geography of Bihar by Eithasab Ahmed
Geography of Bihar by Eithasab AhmedGeography of Bihar by Eithasab Ahmed
Geography of Bihar by Eithasab Ahmed
 
August 2012
August 2012August 2012
August 2012
 
Social Gaming in Asia
Social Gaming in AsiaSocial Gaming in Asia
Social Gaming in Asia
 
Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516
 
44 tushaal
44 tushaal44 tushaal
44 tushaal
 
Tool room & engineering manager
Tool room & engineering managerTool room & engineering manager
Tool room & engineering manager
 

Similaire à Writing jQuery that doesn't suck - London jQuery

Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS DirectivesChristian Lilley
 
Writing JavaScript that doesn't suck
Writing JavaScript that doesn't suckWriting JavaScript that doesn't suck
Writing JavaScript that doesn't suckRoss Bruniges
 
Flash on Tap slides
Flash on Tap slidesFlash on Tap slides
Flash on Tap slidesjkosoy
 
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with MagentoMagento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magentovarien
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagentoImagine
 
Cultivating Cucumber
Cultivating CucumberCultivating Cucumber
Cultivating Cucumberleshill
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기형우 안
 
Javascript - How to avoid the bad parts
Javascript - How to avoid the bad partsJavascript - How to avoid the bad parts
Javascript - How to avoid the bad partsMikko Ohtamaa
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern偉格 高
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPsmueller_sandsmedia
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming Wildan Maulana
 
Core data intermediate Workshop at NSSpain 2013
Core data intermediate Workshop at NSSpain 2013Core data intermediate Workshop at NSSpain 2013
Core data intermediate Workshop at NSSpain 2013Diego Freniche Brito
 
Desacoplando aplicaciones
Desacoplando aplicacionesDesacoplando aplicaciones
Desacoplando aplicacionesAlvaro Videla
 
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBDeveloping RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBNicola Iarocci
 
Using+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsUsing+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsMuhammad Ikram Ul Haq
 
Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011Corey Oordt
 
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.WO Community
 

Similaire à Writing jQuery that doesn't suck - London jQuery (20)

Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS Directives
 
Writing JavaScript that doesn't suck
Writing JavaScript that doesn't suckWriting JavaScript that doesn't suck
Writing JavaScript that doesn't suck
 
Flash on Tap slides
Flash on Tap slidesFlash on Tap slides
Flash on Tap slides
 
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with MagentoMagento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
 
Cultivating Cucumber
Cultivating CucumberCultivating Cucumber
Cultivating Cucumber
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기
 
Javascript - How to avoid the bad parts
Javascript - How to avoid the bad partsJavascript - How to avoid the bad parts
Javascript - How to avoid the bad parts
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
Test your modules
Test your modulesTest your modules
Test your modules
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
 
Core data intermediate Workshop at NSSpain 2013
Core data intermediate Workshop at NSSpain 2013Core data intermediate Workshop at NSSpain 2013
Core data intermediate Workshop at NSSpain 2013
 
Desacoplando aplicaciones
Desacoplando aplicacionesDesacoplando aplicaciones
Desacoplando aplicaciones
 
CommonJS Frameworks
CommonJS FrameworksCommonJS Frameworks
CommonJS Frameworks
 
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBDeveloping RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDB
 
Using+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsUsing+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applications
 
Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011
 
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
 
Introduction To JSFL
Introduction To JSFLIntroduction To JSFL
Introduction To JSFL
 

Dernier

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Dernier (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Writing jQuery that doesn't suck - London jQuery

  • 1. taken by Jeremy Keith - http://www.flickr.com/photos/adactio/ Writing jQuery JavaScript that doesn’t suck Monday, 4 July 2011
  • 2. Introductions Ross Bruniges Monday, 4 July 2011
  • 3. Introductions taken by Mike Morgan - http://www.flickr.com/photos/morgamic/ Ross Bruniges, Web Developer at Mozilla Monday, 4 July 2011
  • 4. Introductions careers.mozilla.com We’re hiring! Monday, 4 July 2011
  • 5. Introductions taken by Mike Morgan - http://www.flickr.com/photos/morgamic/ Ross Bruniges, Regular drinker at Pub Standards Monday, 4 July 2011
  • 6. Introductions taken by Caz Mockett - http://www.flickr.com/photos/rugbymadgirl/ So what am I going to be talking about? Monday, 4 July 2011
  • 7. Introductions taken by Julian Burgess - http://www.flickr.com/photos/aubergene/ A JavaScript mixed bag. Monday, 4 July 2011
  • 8. Organisation Leaving things as you would like them to be found Monday, 4 July 2011
  • 9. Organisation JSLint is a JavaScript program that looks for problems in JavaScript programs. It is a code quality tool. More information on the JS Lint at http://www.jslint.com/lint.html Remember to useJavaScript Lint your eventDelegation Monday, 4 July 2011
  • 10. Organisation application = some large JS app (global) function eatMe() { // accessing the global variable application = false; } eatMe(); application.shouldWork();// now returns false Beware Remember to use eventDelegation global variables, they are easy to overwrite Monday, 4 July 2011
  • 11. Organisation application = some large JS app (global) function eatMe() { // now accessing a local variable var application = false; } eatMe(); application.shouldWork()// now works Beware Remember to use eventDelegation global variables, they are easy to overwrite Monday, 4 July 2011
  • 12. Organisation return { javascript : "fantastic" }; Example by Douglas Crockford Don’t rely on semi-colon insertion to work Remember to use eventDelegation Monday, 4 July 2011
  • 13. Organisation return; // Semicolon inserted, believing the statement has finished. Returns undefined { // Considered to be an anonymous block, doing nothing javascript : "fantastic" };// Semicolon interpreted as an empty dummy line and moved down Example by Douglas Crockford Don’t rely on semi-colon insertion to work Remember to use eventDelegation Monday, 4 July 2011
  • 14. Organisation return { javascript : "fantastic" }; Example by Douglas Crockford Hug your brackets and remember to include your semi-colons Remember to use eventDelegation Monday, 4 July 2011
  • 15. Organisation 1 == true // returns true as 1 is a ‘truthy’ value and gets converted to such 1 === true // returns false as no conversion is applied Remember to use eventDelegation Always use === and !== Monday, 4 July 2011
  • 16. Organisation More Crockford facts at http://crockfordfacts.com/ Remember to for Douglas Do it use eventDelegation Monday, 4 July 2011
  • 17. Organisation $(‘#foo’).click(function(){console.log(‘please stop this madness’);}).end().filter (‘div.urgghhh’) Pain for someone down the line Avoid long chained statements use eventDelegation doesn’t mean Remember to - just because you can that you should. Monday, 4 July 2011
  • 18. Organisation Remember to likes eventDelegation Everyone use a nice chain Monday, 4 July 2011
  • 19. Organisation But you can end up looking use eventDelegationget too much Remember to like a douche if you Monday, 4 July 2011
  • 20. Organisation $(‘#foo’) .click(function(){ console.log(‘please stop this madness’); }) .end() .filter(‘div.urgghhh’); Remember to use eventDelegation This works just fine Monday, 4 July 2011
  • 21. Organisation Remember of a JS Design Pattern Make use to use eventDelegation Monday, 4 July 2011
  • 22. Organisation http://addyosmani.com/blog/essentialjsdesignpatterns/ Remember to use eventDelegation Free book! Monday, 4 July 2011
  • 23. Organisation var clean = function() { var debug = false; var init = function() { console.log(‘fail’); }; return { init : init }; }(); clean.init(); Revealing Module Pattern - clean, tidy and easy to understand Remember to use eventDelegation Monday, 4 July 2011
  • 24. Organisation Remember to well eventDelegation Modules play use with JS loaders Monday, 4 July 2011
  • 25. Organisation Remember over complication Avoid to use eventDelegation Monday, 4 July 2011
  • 26. Organisation Just because you THINK it to use be cool doesn’t mean it will be. Remember might eventDelegation Especially if no one has asked for it. Monday, 4 July 2011
  • 27. Organisation function poorlyThoughtOut() { // OK I’m going to get some elements // add a class or two // parse some data from the elements // remove some DOM elements // parse some data from someplace else // fade the background to yellow to highlight the change // update the screenreader buffer } Don’t stuff your functions until they burst Remember to use eventDelegation Monday, 4 July 2011
  • 28. Organisation function parseData() {} function updateBuffer() {} function betterPlanned() { // OK I’m going to get some elements // add a class or two // parseData() // remove some DOM elements // parseData() // updateBuffer() } Smaller functions are easier useunderstand and more modular Remember to to eventDelegation Monday, 4 July 2011
  • 29. Organisation In your code trigger an event $.trigger(‘carousel_move’); If someone needs it they can use it later $.bind(‘carousel_move’, function(e) { console.log(‘event functionality without needing to alter the existing code base’); }); Custom events to to use for future development Remember allow eventDelegation Monday, 4 July 2011
  • 30. Organisation // // Dear maintainer: // // Once you are done trying to 'optimize' this routine, // and have realized what a terrible mistake that was, // please increment the following counter as a warning // to the next guy: // // total_hours_wasted_here = 39 // comment from stackoverflow thread - http://stackoverflow.com/questions/184618/ Remember to useyour code Comment eventDelegation Monday, 4 July 2011
  • 31. Organisation /** * Change the role of the employee. * @param {integer} employeeId The id of the employee. * @param {string} [newRole] The new role of the employee. */ function recast(employeeId, newRole) { } project homepage at http://code.google.com/p/jsdoc-toolkit/ JSDocToolkit - commentseventDelegation out Remember to use in, documentation Monday, 4 July 2011
  • 32. Organisation /* @name vehicle.Sled#reindeer @function @description Set the reindeer that will pull Santa's sled. @param {string[]} reindeer A list of the reindeer. @example // specifying some reindeer Sled().reindeer(['Dasher', 'Dancer', 'Rudolph', 'Vixen']); */ full article by Frances Berriman at http://24ways.org/2010/documentation-driven-design-for-apis Documentation-Driven Design,eventDelegationcode second Remember to use document first Monday, 4 July 2011
  • 33. Organisation // TODO: Fix this. Fix what? comment from stackoverflow thread - http://stackoverflow.com/questions/184618/ WhateverRemember to use eventDelegation the start. you choose ensure you do it from Monday, 4 July 2011
  • 34. Organisation /** * Always returns true. */ public boolean isAvailable() { return false; } comment from stackoverflow thread - http://stackoverflow.com/questions/184618/ Remember to it upeventDelegation Keep use to date Monday, 4 July 2011
  • 35. Performance diagram from http://www.sapdesignguild.org/ Monday, 4 July 2011
  • 36. Performance taken by pi.kappa - http://www.flickr.com/photos/27890120@N08/ Don’t prematurely optimise - you’re just ASSuming Monday, 4 July 2011
  • 37. Performance $(‘#foo div’) = bad, it will search first for ALL divs in the document; $(‘div.me’) is better it will only search for divs with that specific class $(‘div#me’) = best, all JS parses will look only for that specific element Write good selectors (sizzle parse right to left - in IE6 and 7) Monday, 4 July 2011
  • 38. Performance var expensive-selector = $(“.section:first”), reused-json-object = $.getJSON(‘docs.json’), reusable-regex = /d(b+)d/g; Cache quicker for reuse Monday, 4 July 2011
  • 39. Performance Exit quickly to avoid silent fails Monday, 4 July 2011
  • 40. Performance var elm = $(‘#findMe’); if (!elm.length) { return false; } We now know that this code will only be run if the element actually exists. Exit quickly to avoid silent fails Monday, 4 July 2011
  • 41. Performance from The Mysteries of JavaScript Fu, Dan Webb - http://www.slideshare.net/danwrong/java-script-fu- Remember to use eventDelegation Monday, 4 July 2011
  • 42. Performance .live() example - quick and dirty $('tr').live('click', function(event) { // this == tr element }); Code examples from http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery Remember to use eventDelegation Monday, 4 July 2011
  • 43. Performance .delegate() example - also chainable $('table').delegate('tr', 'click', function(event){ // this == tr element }); Code examples from http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery Remember to use eventDelegation Monday, 4 July 2011
  • 44. Performance Handrolled example - maximum control $('table').bind('click', function(event) { // this == table element var $tr = $(event.target).closest('tr'); }); Code examples from http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery Remember to use eventDelegation Monday, 4 July 2011
  • 45. Performance Cause minimal reflows use eventDelegation in IE) Remember to and repaints (especially Monday, 4 July 2011
  • 46. Performance “Repaint - also known as redraw - is what happens whenever something is made visible when it was not previously visible, or vice versa, without altering the layout of the document.” Quote from http://dev.opera.com/articles/view/efficient-javascript/?page=all Remember to use eventDelegation Repaints Monday, 4 July 2011
  • 47. Performance “whenever the DOM tree is manipulated, whenever a style is changed that affects the layout, whenever the className property of an element is changed, or whenever the browser window size is changed... In many cases, they are equivalent to laying out the entire page again.” Quote from http://dev.opera.com/articles/view/efficient-javascript/?page=all Remember toReflows use eventDelegation Monday, 4 July 2011
  • 48. Performance Remember to use eventDelegation Use the latest version of jQuery! Monday, 4 July 2011
  • 49. Don’t forget your accessibility taken by Drew McLellan - http://www.flickr.com/photos/drewm/ Monday, 4 July 2011
  • 50. Don’t forget your accessibility Don’t forget your focus (and blur) Monday, 4 July 2011
  • 51. Don’t forget your accessibility $(‘#foo’).bind(‘mouseenter focus’, function(e) { code goes here }); $(‘#foo’).bind(‘mouseleave blur’, function(e) { code goes here }); If you use .bind (opposed to .click) you can include multiple events Monday, 4 July 2011
  • 52. Don’t forget your accessibility Invalid mark-up is still invalid mark-up even when inserted via JS Monday, 4 July 2011
  • 53. Don’t forget your accessibility Remember to update the screenreader buffer Monday, 4 July 2011
  • 54. Don’t forget your accessibility 1. Update the value of a hidden input field 2. Ensure that you have a tabIndex value of -1 on the element that you’ve altered 3. .focus() on the newly inserted content The old(ish) way Monday, 4 July 2011
  • 55. Don’t forget your accessibility “Live region markup allows web page authors to specify when and how live changes to specific areas of a web page should be spoken or shown on a Braille display by a screen reader.” Read more at https://developer.mozilla.org/en/AJAX/WAI_ARIA_Live_Regions The new(ish) way - ARIA live regions Monday, 4 July 2011
  • 56. Don’t forget your accessibility aria-live - sets the frequency of updates to AT aria-controls - associates a control with an area. All actions on that control are announced by AT aria-relevant - states what changes to the live region are to be announced to AT Read more at https://developer.mozilla.org/en/AJAX/WAI_ARIA_Live_Regions The new(ish) way - ARIA live regions Monday, 4 July 2011
  • 57. Don’t forget Performance your ‘edge cases’ Monday, 4 July 2011
  • 58. Don’t forget your ‘edge cases’ If things can goto use eventDelegation Remember wrong then normally will Monday, 4 July 2011
  • 59. Don’t forget your ‘edge cases’ Remember to code for when the server doesn’t return a value - it might be down or the app might be broken. The server might take longer to reply than expected and cause a timeout meaning an empty return value. If things can go wrong then normally will Monday, 4 July 2011
  • 60. Don’t forget your ‘edge cases’ $.ajax is the backbone to all jQuery AJAX methods like $.getScript or $.getJSON and allows for much greater flexibility. $.ajax({ url : “foo.php”, dataType : “json”, success : function(data) { gets sent the JSON response }, error : function() { gets sent the error type and text }, timeout : 1000 }); Remember toto the rescue $.ajax use eventDelegation Monday, 4 July 2011
  • 61. Don’t forget your ‘edge cases’ - like other browsers! Remember toause eventDelegation jQuery isn’t 100% magic bullet Monday, 4 July 2011
  • 62. Thanks for listening! http://bit.ly/ross-london-jquery Remember to use eventDelegation Looking for the links? Monday, 4 July 2011
  • 63. Taken by Mark Klotz - http://www.flickr.com/photos/markklotz/ Remember toCheers! use eventDelegation Monday, 4 July 2011