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

Writing jQuery JavaScript that doesn’t suck
Introductions




                Ross Bruniges
Introductions




                   taken by Phil Whiteside - http://www.flickr.com/photos/philliecasablanca/

           Ross Bruniges, Web Developer at Nature.com
Introductions




                Ross Bruniges, Occasional Author
Introductions




                            taken by Patrick Griffiths - http://www.flickr.com/photos/ptg/

          Ross Bruniges, Regular drinker at Pub Standards
Introductions




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

                So what am I going to be talking about?
Introductions




                                  taken by PJ Barry - http://www.flickr.com/photos/actel/

                A new years refresher after a long 2010
Introductions




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

                A JavaScript mixed bag.
Organisation




               Yes this is my wardrobe
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
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
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
Organisation




  return
  {
    javascript : "fantastic"
  };




                                                 Example by Douglas Crockford

               Don’t rely on semi-colon insertion to work
                  Remember to use eventDelegation
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
Organisation




  return {
    javascript : "fantastic"
  };




                                             Example by Douglas Crockford

   Hug your brackets and remember to include your semi-colons
               Remember to use eventDelegation
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 !==
Organisation




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

               Remember to for Douglas
                     Do it use eventDelegation
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.
Organisation




               Remember to likes eventDelegation
                  Everyone use a nice chain
Organisation




   But you can end up looking use eventDelegationget too much
                Remember to like a douche if you
Organisation




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




                Remember to use eventDelegation
                     This works just fine
Organisation




               Remember of a JS Design Pattern
                Make use to use eventDelegation
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
Organisation




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

               Remember to use eventDelegation
                        Free book!
Organisation




               Remember over complication
                   Avoid to use eventDelegation
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.
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
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
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
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
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
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
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
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
Performance




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




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

        Don’t prematurely optimise - you’re just ASSuming
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)
Performance




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




                Cache quicker for reuse
Performance




              Exit quickly to avoid silent fails
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
Performance




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

                       Remember to use eventDelegation
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
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
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
Performance




       Cause minimal reflows use eventDelegation in IE)
              Remember to and repaints (especially
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
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
Don’t forget your accessibility




                            taken by Drew McLellan - http://www.flickr.com/photos/drewm/
Don’t forget your accessibility




                  Don’t forget your focus (and blur)
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
Don’t forget your accessibility




   Invalid mark-up is still invalid mark-up even when inserted via JS
Don’t forget your accessibility




            Remember to update the screenreader buffer
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
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
Don’t forget your accessibility


  aria-live - sets the frequency of updates to AT

  aria-controls - assosiates 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
Don’t forget
Performance your ‘edge cases’
Don’t forget your ‘edge cases’




              If things can goto use eventDelegation
                  Remember wrong then normally will
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
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
Don’t forget your ‘edge cases’




  ALL current versions of IE can’t apply styles to
  the new HTML5 elements without the use of
  JavaScript.




                   More information on the HTML5shiv at http://code.google.com/p/html5shiv/

                 Remember tothe HTML5 shiv
                     Beware use eventDelegation
Don’t forget your ‘edge cases’




  Lots of clever people recommend the use of Remy
  Sharps HTML5shiv to force IE into rendering these
  elements after it was found that creating empty
  pointers to them with JavaScript makes them
  styleable.




                   More information on the HTML5shiv at http://code.google.com/p/html5shiv/

                 Remember tothe HTML5 shiv
                     Beware use eventDelegation
Don’t forget your ‘edge cases’




  So JS is being used to ensure CSS works.




                   More information on the HTML5shiv at http://code.google.com/p/html5shiv/

                 Remember tothe HTML5 shiv
                     Beware use eventDelegation
Don’t forget your ‘edge cases’




                 Remember to use eventDelegation
                              Fail?
Don’t forget your ‘edge cases’




  <div class=”section”>
    <section>
    </section>
  </div>

  You can now apply CSS to .section and be safe in
  the knowledge that they will always be applied.




                 Remember A safereventDelegation
                          to use way
Don’t forget your ‘edge cases’




          Clients wouldn’t like their site looking like this...
                Remember to use eventDelegation
Questions?
Taken by Mark Klotz - http://www.flickr.com/photos/markklotz/

Remember toCheers!
            use eventDelegation

Contenu connexe

Tendances

jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionPaul Irish
 
Ditching JQuery
Ditching JQueryDitching JQuery
Ditching JQueryhowlowck
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fabio Akita
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesjerryorr
 
Making your Angular.js Application accessible
Making your Angular.js Application accessibleMaking your Angular.js Application accessible
Making your Angular.js Application accessibleDirk Ginader
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
ES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorDavid Rodenas
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performancekaven yan
 
GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSNicolas Embleton
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Desarrollo para Android con Groovy
Desarrollo para Android con GroovyDesarrollo para Android con Groovy
Desarrollo para Android con GroovySoftware Guru
 
Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricksNLJUG
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 

Tendances (20)

An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 
Ditching JQuery
Ditching JQueryDitching JQuery
Ditching JQuery
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009
 
Advanced Silverlight
Advanced SilverlightAdvanced Silverlight
Advanced Silverlight
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
 
Making your Angular.js Application accessible
Making your Angular.js Application accessibleMaking your Angular.js Application accessible
Making your Angular.js Application accessible
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
ES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD Calculator
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performance
 
Step objects
Step objectsStep objects
Step objects
 
GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JS
 
meet.js - QooXDoo
meet.js - QooXDoomeet.js - QooXDoo
meet.js - QooXDoo
 
Javascript in Plone
Javascript in PloneJavascript in Plone
Javascript in Plone
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Desarrollo para Android con Groovy
Desarrollo para Android con GroovyDesarrollo para Android con Groovy
Desarrollo para Android con Groovy
 
Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricks
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Ajax Security
Ajax SecurityAjax Security
Ajax Security
 

En vedette

#doctorbridge So... is this my country? Un paese cosi?
#doctorbridge So... is this my country? Un paese cosi?#doctorbridge So... is this my country? Un paese cosi?
#doctorbridge So... is this my country? Un paese cosi?Salvo Fedele
 
Tatrabanka LOX Facebook ad Case Study
Tatrabanka LOX Facebook ad Case StudyTatrabanka LOX Facebook ad Case Study
Tatrabanka LOX Facebook ad Case StudyEtarget
 
Ako zostaviť moderné a výživné menu
Ako zostaviť moderné a výživné menuAko zostaviť moderné a výživné menu
Ako zostaviť moderné a výživné menuEtarget
 
Pentagon
PentagonPentagon
PentagonMrG
 
Synergy of TV formats and contextual PPC
Synergy of TV formats and contextual PPCSynergy of TV formats and contextual PPC
Synergy of TV formats and contextual PPCEtarget
 
i lavori infiniti del progetto "area pediatrica della città di Palermo"
i lavori infiniti del progetto "area pediatrica della città di Palermo"i lavori infiniti del progetto "area pediatrica della città di Palermo"
i lavori infiniti del progetto "area pediatrica della città di Palermo"Salvo Fedele
 
Prokariotoen gainazaleko egiturak
Prokariotoen gainazaleko egiturakProkariotoen gainazaleko egiturak
Prokariotoen gainazaleko egiturakJuan Arbulu Arin
 
Anatomy of a Business Card
Anatomy of a Business CardAnatomy of a Business Card
Anatomy of a Business CardRoss Bruniges
 
D U C A T I O N S E X U E L L E H3 R
D U C A T I O N S E X U E L L E   H3 RD U C A T I O N S E X U E L L E   H3 R
D U C A T I O N S E X U E L L E H3 Rguestfaa252
 
Enrich the web with comments
Enrich the web with commentsEnrich the web with comments
Enrich the web with commentsRoss Bruniges
 
Mikroorganismoaen zitoplasma eta osaera
Mikroorganismoaen zitoplasma eta osaeraMikroorganismoaen zitoplasma eta osaera
Mikroorganismoaen zitoplasma eta osaeraJuan Arbulu Arin
 

En vedette (20)

#doctorbridge So... is this my country? Un paese cosi?
#doctorbridge So... is this my country? Un paese cosi?#doctorbridge So... is this my country? Un paese cosi?
#doctorbridge So... is this my country? Un paese cosi?
 
Tatrabanka LOX Facebook ad Case Study
Tatrabanka LOX Facebook ad Case StudyTatrabanka LOX Facebook ad Case Study
Tatrabanka LOX Facebook ad Case Study
 
Ako zostaviť moderné a výživné menu
Ako zostaviť moderné a výživné menuAko zostaviť moderné a výživné menu
Ako zostaviť moderné a výživné menu
 
Pentagon
PentagonPentagon
Pentagon
 
Synergy of TV formats and contextual PPC
Synergy of TV formats and contextual PPCSynergy of TV formats and contextual PPC
Synergy of TV formats and contextual PPC
 
i lavori infiniti del progetto "area pediatrica della città di Palermo"
i lavori infiniti del progetto "area pediatrica della città di Palermo"i lavori infiniti del progetto "area pediatrica della città di Palermo"
i lavori infiniti del progetto "area pediatrica della città di Palermo"
 
821
821821
821
 
Lek monitoreei harrera
Lek monitoreei harreraLek monitoreei harrera
Lek monitoreei harrera
 
Moodle wiki aurkezpenak
Moodle wiki aurkezpenakMoodle wiki aurkezpenak
Moodle wiki aurkezpenak
 
Prokariotoen gainazaleko egiturak
Prokariotoen gainazaleko egiturakProkariotoen gainazaleko egiturak
Prokariotoen gainazaleko egiturak
 
Anatomy of a Business Card
Anatomy of a Business CardAnatomy of a Business Card
Anatomy of a Business Card
 
Slideshare
SlideshareSlideshare
Slideshare
 
Bakterioen metabolismoa
Bakterioen metabolismoaBakterioen metabolismoa
Bakterioen metabolismoa
 
Lagun gida
Lagun gidaLagun gida
Lagun gida
 
Fotosintesia
FotosintesiaFotosintesia
Fotosintesia
 
D U C A T I O N S E X U E L L E H3 R
D U C A T I O N S E X U E L L E   H3 RD U C A T I O N S E X U E L L E   H3 R
D U C A T I O N S E X U E L L E H3 R
 
E portafolioa gida
E portafolioa gidaE portafolioa gida
E portafolioa gida
 
Enrich the web with comments
Enrich the web with commentsEnrich the web with comments
Enrich the web with comments
 
Mikroorganismoaen zitoplasma eta osaera
Mikroorganismoaen zitoplasma eta osaeraMikroorganismoaen zitoplasma eta osaera
Mikroorganismoaen zitoplasma eta osaera
 
Mobile Web Design Code
Mobile Web Design CodeMobile Web Design Code
Mobile Web Design Code
 

Similaire à Writing JavaScript that doesn't suck

Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.Alberto Naranjo
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS InternalEyal Vardi
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e bigAndy Peterson
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War StoriesJakub Zalas
 
The Naked Bundle - Tryout
The Naked Bundle - TryoutThe Naked Bundle - Tryout
The Naked Bundle - TryoutMatthias Noback
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascriptmpnkhan
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third PluginJustin Ryan
 

Similaire à Writing JavaScript that doesn't suck (20)

Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
DrupalCon jQuery
DrupalCon jQueryDrupalCon jQuery
DrupalCon jQuery
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War Stories
 
The Naked Bundle - Tryout
The Naked Bundle - TryoutThe Naked Bundle - Tryout
The Naked Bundle - Tryout
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third Plugin
 

Dernier

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
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
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Dernier (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
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...
 
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
 
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...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Writing JavaScript that doesn't suck

  • 1. taken by Jeremy Keith - http://www.flickr.com/photos/adactio/ Writing jQuery JavaScript that doesn’t suck
  • 2. Introductions Ross Bruniges
  • 3. Introductions taken by Phil Whiteside - http://www.flickr.com/photos/philliecasablanca/ Ross Bruniges, Web Developer at Nature.com
  • 4. Introductions Ross Bruniges, Occasional Author
  • 5. Introductions taken by Patrick Griffiths - http://www.flickr.com/photos/ptg/ Ross Bruniges, Regular drinker at Pub Standards
  • 6. Introductions taken by Caz Mockett - http://www.flickr.com/photos/rugbymadgirl/ So what am I going to be talking about?
  • 7. Introductions taken by PJ Barry - http://www.flickr.com/photos/actel/ A new years refresher after a long 2010
  • 8. Introductions taken by Julian Burgess - http://www.flickr.com/photos/aubergene/ A JavaScript mixed bag.
  • 9. Organisation Yes this is my wardrobe
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. Organisation return { javascript : "fantastic" }; Example by Douglas Crockford Don’t rely on semi-colon insertion to work Remember to use eventDelegation
  • 14. 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
  • 15. Organisation return { javascript : "fantastic" }; Example by Douglas Crockford Hug your brackets and remember to include your semi-colons Remember to use eventDelegation
  • 16. 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 !==
  • 17. Organisation More Crockford facts at http://crockfordfacts.com/ Remember to for Douglas Do it use eventDelegation
  • 18. 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.
  • 19. Organisation Remember to likes eventDelegation Everyone use a nice chain
  • 20. Organisation But you can end up looking use eventDelegationget too much Remember to like a douche if you
  • 21. Organisation $(‘#foo’) .click(function(){ console.log(‘please stop this madness’); }) .end() .filter(‘div.urgghhh’); Remember to use eventDelegation This works just fine
  • 22. Organisation Remember of a JS Design Pattern Make use to use eventDelegation
  • 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
  • 24. Organisation http://addyosmani.com/blog/essentialjsdesignpatterns/ Remember to use eventDelegation Free book!
  • 25. Organisation Remember over complication Avoid to use eventDelegation
  • 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.
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 35. Performance diagram from http://www.sapdesignguild.org/
  • 36. Performance taken by pi.kappa - http://www.flickr.com/photos/27890120@N08/ Don’t prematurely optimise - you’re just ASSuming
  • 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)
  • 38. Performance var expensive-selector = $(“.section:first”), reused-json-object = $.getJSON(‘docs.json’), reusable-regex = /d(b+)d/g; Cache quicker for reuse
  • 39. Performance Exit quickly to avoid silent fails
  • 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
  • 41. Performance from The Mysteries of JavaScript Fu, Dan Webb - http://www.slideshare.net/danwrong/java-script-fu- Remember to use eventDelegation
  • 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
  • 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
  • 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
  • 45. Performance Cause minimal reflows use eventDelegation in IE) Remember to and repaints (especially
  • 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
  • 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
  • 48. Don’t forget your accessibility taken by Drew McLellan - http://www.flickr.com/photos/drewm/
  • 49. Don’t forget your accessibility Don’t forget your focus (and blur)
  • 50. 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
  • 51. Don’t forget your accessibility Invalid mark-up is still invalid mark-up even when inserted via JS
  • 52. Don’t forget your accessibility Remember to update the screenreader buffer
  • 53. 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
  • 54. 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
  • 55. Don’t forget your accessibility aria-live - sets the frequency of updates to AT aria-controls - assosiates 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
  • 57. Don’t forget your ‘edge cases’ If things can goto use eventDelegation Remember wrong then normally will
  • 58. 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
  • 59. 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
  • 60. Don’t forget your ‘edge cases’ ALL current versions of IE can’t apply styles to the new HTML5 elements without the use of JavaScript. More information on the HTML5shiv at http://code.google.com/p/html5shiv/ Remember tothe HTML5 shiv Beware use eventDelegation
  • 61. Don’t forget your ‘edge cases’ Lots of clever people recommend the use of Remy Sharps HTML5shiv to force IE into rendering these elements after it was found that creating empty pointers to them with JavaScript makes them styleable. More information on the HTML5shiv at http://code.google.com/p/html5shiv/ Remember tothe HTML5 shiv Beware use eventDelegation
  • 62. Don’t forget your ‘edge cases’ So JS is being used to ensure CSS works. More information on the HTML5shiv at http://code.google.com/p/html5shiv/ Remember tothe HTML5 shiv Beware use eventDelegation
  • 63. Don’t forget your ‘edge cases’ Remember to use eventDelegation Fail?
  • 64. Don’t forget your ‘edge cases’ <div class=”section”> <section> </section> </div> You can now apply CSS to .section and be safe in the knowledge that they will always be applied. Remember A safereventDelegation to use way
  • 65. Don’t forget your ‘edge cases’ Clients wouldn’t like their site looking like this... Remember to use eventDelegation
  • 67. Taken by Mark Klotz - http://www.flickr.com/photos/markklotz/ Remember toCheers! use eventDelegation