SlideShare a Scribd company logo
1 of 62
Download to read offline
jQuery
In with the new,
out with the old.
Agenda
๏ Understanding jQuery
๏ What's new & interesting
๏ Where you don't need it
Grokking
jQuery
DOM library
$('div').append(html).click(doStuff);
Just a CSS selector


$('div').append(html).click(doStuff);
$('div').append(html).click(doStuff);
$('div').append(html).click(doStuff);
if ( $('foo') ) {
  doAmazing();
}
1) $('foo')
2) $()
3) []
4) [].join(',') // works
if ( $('foo') ) {
  doAmazing();
}
if ( $('foo').length ) {
  doAmazing();
}
If your jQuery code fails,
and there's no error:

it's the selector
DOM Navigation
Find

Changes the collection
Filter

 Creates a subset
Debugging
New
Stuff
Ajax changes
  & Deferreds
$.get('foo.html', function (html) {
var jqXHR = $.get('foo.html');
  $('#latest').append(html);
});
jqXHR.done(function (html) {
  $('#latest').append(html);
});
$.ajax({
  url: 'foo.json',
  dataType: 'json',
  success: function () {
     // this === xhr
  },
  error: function () {

  }
});
$.ajax({
  url: 'foo.json',
  dataType: 'json',
  context: document.body,
  success: function () {
     // this === body element
  },
  error: function () {

  }
});
var jqXHR = $.ajax({
  url: 'foo.json',
  dataType: 'json',
  context: document.body
});

jqXHR.then(success, fail);
var jqXHR = $.ajax({
  url: 'foo.json',
  dataType: 'json',
  context: document.body
});

jqXHR.then(success, fail);

// much later in the code

jqXHR.done(success2);
jqXHR is a
promise
var jqXHR = $.ajax({
  url: 'foo.json',
  dataType: 'json',
  context: document.body
});

// much later in the code

jqXHR.done(success);
.done(ok)   // success
.fail(fail) // error
.always(fn) // complete
.then(ok, fail)
var dfd = $.Deferred();


    .resolve
    .reject
    .promise
var jqXHR = $.ajax({
  url: 'foo.json',
  dataType: 'json',
  context: document.body
});

// much later in the code

jqXHR.done(success);
function save(data) {
  var dfd = new $.Deferred();

    // some validation done...

    if (!valid) {
      dfd.reject(reason);
    } else {
      $.ajax({
        url: '/app/save',
        data: data,
        success: dfd.resolve,
        error: dfd.reject
      });
    }

    return dfd.promise();
}
nction save(data) {
var dfd = new $.Deferred();

// some validation done...

if (!valid) {             save({ /* some data */ })
  dfd.reject(reason);       .done(function () {
} else {                       // show it's all good
  $.ajax({
                            })
    url: '/app/save',
    data: data,             .fail(function (reason) {
    success: dfd.resolve,      // shows reason
    error: dfd.reject       });
  });
}

return dfd.promise();
$.when
$.when
var $boxes = $('div'),
    rand = Math.random,
    dfds = [];

for (var i = 0; i < 3; i++) {
  dfds.push($.Deferred());
  $boxes.eq(i).fadeTo(rand() * 5000, 1, dfds[i].resolve);
}

$.when.apply($, dfds).done(function () {
  alert('all done!');
});
$.sub()
(function ($) {
  $ = $.sub(); // sandbox $.fn

  $.fn.logger = function () {
    return this.each(function(){
      console.log(this)
    });
  }

  // my code that uses .logger()
})(jQuery);

// now: $.fn.logger === undefined
(function ($) {
  $ = $.sub(); // sandbox $.fn

  $.fn.logger = function () {
    return this.each(function(){
      console.log(this)
    });
  }

  // my code that uses .logger()
})(jQuery);

// now: $.fn.logger === undefined
Doing it
wrong
.ready?
...
<!-- all my funky markup -->
...
<script>
$(document).ready(function () {
  // add the extra funk
});
</script>
</body>
</html>
.ready?
...
<!-- all my funky markup -->
...
<script>

  // add the extra funk

</script>
</body>
</html>
Add class
...
<!-- all my funky markup -->
...
<script>

$('#foo').addClass('amazing');


</script>
</body>
</html>
Add class
...
<!-- all my funky markup -->
...
<script>

var f = document.getElementById('foo');
foo.className += ' amazing';

</script>
</body>
</html>
Effects vs. CSS
๏ Ifthe browser can do it
 natively, let it do it
 natively.
๏ Noone lost business because
 IE didn't do a cross fade.
return false
$('a').click(function () {
  // do the magic
  amazingMagic();

  return false;
});
return false

๏ Do you know what's happening?
๏ event.preventDefault()
๏ event.stopPropagation()
Get to know this
$('a').click(function (e) {
  e.preventDefault();

  var href = $(this).attr('href');
  // do the magic
  amazingMagic(href);
});
Get to know this
$('a').click(function (e) {
  e.preventDefault();

  var href = this.href;
  // do the magic
  amazingMagic(href);
});
Poorly designed plugins
$.fn.myplugin = function () {
  var me = $(this).each(function() {
    return $(this).bind('someEvent', function () {
      // does something
    });
  });

  return me;
};
$.fn.myplugin = function () {
  var me = $(this).each(fn);

  return me;
};
$.fn.myplugin = function () {
  return $(this).each(fn);
};
$.fn.myplugin = function () {
  return $(this).each(function() {
    return $(this).bind('someEvent', function () {
      // does something
    });
  });
};
$.fn.myplugin = function () {
  return $(this).each(function() {
    return $(this).bind('someEvent', function () {
      // does something
    });
  });
};
$.fn.myplugin = function () {
  return this.each(function() {
    return $(this).bind('someEvent', function () {
      // does something
    });
  });
};
$.fn.myplugin = function () {
  return this.each(function() {
    return $(this).bind('someEvent', function () {
      // does something
    });
  });
};
$.fn.myplugin = function () {
  return this.each(function() {
    $(this).bind('someEvent', function () {
      // does something
    });
  });
};
$.fn.myplugin = function () {
  return this.each(function() {
    $(this).bind('someEvent', function () {
      // does something
    });
  });
};
$.fn.myplugin = function () {
   return this.bind('someEvent', function () {
     // does something
  });
};
(function ($) {
  $.fn.myplugin = function () {
    return this.bind('someEvent', function () {
       // does something
     });
  };
})(jQuery);
Questions?
@rem
remy@leftlogic.com

More Related Content

What's hot

PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersKacper Gunia
 
History of jQuery
History of jQueryHistory of jQuery
History of jQueryjeresig
 
Report: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors FieldReport: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors Fieldfabulouspsychop39
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesMarcello Duarte
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile ProcessEyal Vardi
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesEyal Vardi
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysNicholas Dionysopoulos
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDAleix Vergés
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 

What's hot (20)

PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Report: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors FieldReport: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors Field
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examples
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeys
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
 
logic321
logic321logic321
logic321
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 

Viewers also liked

jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Eventsdmethvin
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
Presentational jQuery
Presentational jQueryPresentational jQuery
Presentational jQueryDoug Neiner
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreRemy Sharp
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.jsDoug Neiner
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQueryRemy Sharp
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryRemy Sharp
 
Contextual jQuery
Contextual jQueryContextual jQuery
Contextual jQueryDoug Neiner
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIsRemy Sharp
 

Viewers also liked (11)

jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Presentational jQuery
Presentational jQueryPresentational jQuery
Presentational jQuery
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
Contextual jQuery
Contextual jQueryContextual jQuery
Contextual jQuery
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 

Similar to Understanding jQuery and New Features

How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...Mathias Bynens
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Knowgirish82
 
Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tipsanubavam-techkt
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformanceJonas De Smet
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
Building Evented Single Page Applications
Building Evented Single Page ApplicationsBuilding Evented Single Page Applications
Building Evented Single Page ApplicationsSteve Smith
 
Building evented single page applications
Building evented single page applicationsBuilding evented single page applications
Building evented single page applicationsSteve Smith
 
Building Robust jQuery Plugins
Building Robust jQuery PluginsBuilding Robust jQuery Plugins
Building Robust jQuery PluginsJörn Zaefferer
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in actionJace Ju
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015Fernando Daciuk
 
R57shell
R57shellR57shell
R57shellady36
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 

Similar to Understanding jQuery and New Features (20)

jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 
Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tips
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Building Evented Single Page Applications
Building Evented Single Page ApplicationsBuilding Evented Single Page Applications
Building Evented Single Page Applications
 
Building evented single page applications
Building evented single page applicationsBuilding evented single page applications
Building evented single page applications
 
Building Robust jQuery Plugins
Building Robust jQuery PluginsBuilding Robust jQuery Plugins
Building Robust jQuery Plugins
 
Deferred
DeferredDeferred
Deferred
 
Txjs
TxjsTxjs
Txjs
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
R57shell
R57shellR57shell
R57shell
 
Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 

More from Remy Sharp

Forget the Web
Forget the WebForget the Web
Forget the WebRemy Sharp
 
Interaction Implementation
Interaction ImplementationInteraction Implementation
Interaction ImplementationRemy Sharp
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?Remy Sharp
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsRemy Sharp
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for MobileRemy Sharp
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with WingsRemy Sharp
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the webRemy Sharp
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIsRemy Sharp
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless AppsRemy Sharp
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & FriendsRemy Sharp
 
jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009Remy Sharp
 

More from Remy Sharp (14)

Forget the Web
Forget the WebForget the Web
Forget the Web
 
Interaction Implementation
Interaction ImplementationInteraction Implementation
Interaction Implementation
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for Mobile
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with Wings
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
TwitterLib.js
TwitterLib.jsTwitterLib.js
TwitterLib.js
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIs
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & Friends
 
HTML5 JS APIs
HTML5 JS APIsHTML5 JS APIs
HTML5 JS APIs
 
jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 

Understanding jQuery and New Features

  • 1. jQuery In with the new, out with the old.
  • 2. Agenda ๏ Understanding jQuery ๏ What's new & interesting ๏ Where you don't need it
  • 6. Just a CSS selector $('div').append(html).click(doStuff);
  • 9. if ( $('foo') ) { doAmazing(); }
  • 10. 1) $('foo') 2) $() 3) [] 4) [].join(',') // works
  • 11. if ( $('foo') ) { doAmazing(); }
  • 12. if ( $('foo').length ) { doAmazing(); }
  • 13. If your jQuery code fails, and there's no error: it's the selector
  • 18.
  • 20. Ajax changes & Deferreds
  • 21. $.get('foo.html', function (html) { var jqXHR = $.get('foo.html'); $('#latest').append(html); }); jqXHR.done(function (html) { $('#latest').append(html); });
  • 22. $.ajax({ url: 'foo.json', dataType: 'json', success: function () { // this === xhr }, error: function () { } });
  • 23. $.ajax({ url: 'foo.json', dataType: 'json', context: document.body, success: function () { // this === body element }, error: function () { } });
  • 24. var jqXHR = $.ajax({ url: 'foo.json', dataType: 'json', context: document.body }); jqXHR.then(success, fail);
  • 25. var jqXHR = $.ajax({ url: 'foo.json', dataType: 'json', context: document.body }); jqXHR.then(success, fail); // much later in the code jqXHR.done(success2);
  • 27.
  • 28.
  • 29. var jqXHR = $.ajax({ url: 'foo.json', dataType: 'json', context: document.body }); // much later in the code jqXHR.done(success);
  • 30. .done(ok) // success .fail(fail) // error .always(fn) // complete .then(ok, fail)
  • 31. var dfd = $.Deferred(); .resolve .reject .promise
  • 32. var jqXHR = $.ajax({ url: 'foo.json', dataType: 'json', context: document.body }); // much later in the code jqXHR.done(success);
  • 33. function save(data) { var dfd = new $.Deferred(); // some validation done... if (!valid) { dfd.reject(reason); } else { $.ajax({ url: '/app/save', data: data, success: dfd.resolve, error: dfd.reject }); } return dfd.promise(); }
  • 34. nction save(data) { var dfd = new $.Deferred(); // some validation done... if (!valid) { save({ /* some data */ }) dfd.reject(reason); .done(function () { } else { // show it's all good $.ajax({ }) url: '/app/save', data: data, .fail(function (reason) { success: dfd.resolve, // shows reason error: dfd.reject }); }); } return dfd.promise();
  • 36. $.when var $boxes = $('div'), rand = Math.random,     dfds = []; for (var i = 0; i < 3; i++) {   dfds.push($.Deferred());   $boxes.eq(i).fadeTo(rand() * 5000, 1, dfds[i].resolve); } $.when.apply($, dfds).done(function () {   alert('all done!'); });
  • 38. (function ($) { $ = $.sub(); // sandbox $.fn $.fn.logger = function () { return this.each(function(){ console.log(this) }); } // my code that uses .logger() })(jQuery); // now: $.fn.logger === undefined
  • 39. (function ($) { $ = $.sub(); // sandbox $.fn $.fn.logger = function () { return this.each(function(){ console.log(this) }); } // my code that uses .logger() })(jQuery); // now: $.fn.logger === undefined
  • 41. .ready? ... <!-- all my funky markup --> ... <script> $(document).ready(function () { // add the extra funk }); </script> </body> </html>
  • 42. .ready? ... <!-- all my funky markup --> ... <script> // add the extra funk </script> </body> </html>
  • 43. Add class ... <!-- all my funky markup --> ... <script> $('#foo').addClass('amazing'); </script> </body> </html>
  • 44. Add class ... <!-- all my funky markup --> ... <script> var f = document.getElementById('foo'); foo.className += ' amazing'; </script> </body> </html>
  • 45. Effects vs. CSS ๏ Ifthe browser can do it natively, let it do it natively. ๏ Noone lost business because IE didn't do a cross fade.
  • 46. return false $('a').click(function () { // do the magic amazingMagic(); return false; });
  • 47. return false ๏ Do you know what's happening? ๏ event.preventDefault() ๏ event.stopPropagation()
  • 48. Get to know this $('a').click(function (e) { e.preventDefault(); var href = $(this).attr('href'); // do the magic amazingMagic(href); });
  • 49. Get to know this $('a').click(function (e) { e.preventDefault(); var href = this.href; // do the magic amazingMagic(href); });
  • 51. $.fn.myplugin = function () {   var me = $(this).each(function() {     return $(this).bind('someEvent', function () {       // does something     });   });   return me; };
  • 52. $.fn.myplugin = function () {   var me = $(this).each(fn);   return me; };
  • 53. $.fn.myplugin = function () {   return $(this).each(fn); };
  • 54. $.fn.myplugin = function () {   return $(this).each(function() {     return $(this).bind('someEvent', function () {       // does something     });   }); };
  • 55. $.fn.myplugin = function () {   return $(this).each(function() {     return $(this).bind('someEvent', function () {       // does something     });   }); };
  • 56. $.fn.myplugin = function () {   return this.each(function() {     return $(this).bind('someEvent', function () {       // does something     });   }); };
  • 57. $.fn.myplugin = function () {   return this.each(function() {     return $(this).bind('someEvent', function () {       // does something     });   }); };
  • 58. $.fn.myplugin = function () {   return this.each(function() {     $(this).bind('someEvent', function () {       // does something     });   }); };
  • 59. $.fn.myplugin = function () {   return this.each(function() {     $(this).bind('someEvent', function () {       // does something     });   }); };
  • 60. $.fn.myplugin = function () { return this.bind('someEvent', function () {   // does something   }); };
  • 61. (function ($) { $.fn.myplugin = function () {   return this.bind('someEvent', function () {     // does something   }); }; })(jQuery);