SlideShare a Scribd company logo
JQUERY 1.5
amsterdamjs meetup - February 8th 2011
         @mennovanslooten
IN THIS PRESENTATION...

• New   features        • Improvements

 • jQuery.sub()          • jQuery.ajax()

 • Deferred   objects    • Performance
BUT FIRST...
WHO HERE USES JQUERY?
JQUERY MICRO TUTORIAL

// jQuery is...
// a function you can call to query or create DOM elements:

  var old_element = $(‘#some > .css[selector]’);
  var new_element = $(‘<div id=”hello”><span>world</span></div>’);
JQUERY MICRO TUTORIAL

// This function always returns an array-like collection with
// lots of convenient chain-able methods.

  $(‘#target’)
       .empty()
       .append(new_element);
JQUERY MICRO TUTORIAL

// attaching events
some_element.bind(‘click’, function(e) {
    // handler code
});

// triggering events
some_element.trigger(‘click’);
JQUERY MICRO TUTORIAL

// custom events
some_element.bind(‘whatever’, function(e) {
    // handler code
});

// namespaced events
some_element.bind(‘click.myapp’, function(e) {
    // handler code
});
JQUERY MICRO TUTORIAL
// jQuery is also...
// a collection of useful utilities (not chain-able)

  var a = [0, 1, 2, 3];
  $.each(a, function(i, val) {
      alert(‘Index ‘ + i + ‘ has value ‘ + val);
  });

  var b = $.isArray(a);
JQUERY MICRO TUTORIAL
// ajax: load directly into element
$(‘#target’).load(‘file.html’);



// fine-grained control
$.ajax({
    url     : ‘file.html’,
    type    : ‘POST’,
    async : false,
    success: function(data, status, jqXHR) {
         // handle response
    }
});
THE NEW STUFF...
1.5 IMPROVEMENT:
                    AJAX
• complete   rewrite

• implemented   as a “deferred
 object”
NEW 1.5 FEATURE:
          DEFERRED OBJECTS


A deferred object is a chainable utility object that can register
multiple callbacks into callback queues, invoke callback queues,
 and relay the success or failure state of any synchronous or
                     asynchronous function.
WHAT?
DEFERRED AJAX EXAMPLE
// the old way
var success;
$.ajax(‘file.php’, {
    success : function() { success = true; },
    error   : function() { success = false; }
});



// somewhere else
if (success) {
    // ...
} else {
    // ....
}
DEFERRED AJAX EXAMPLE

// the new way
var req = $.ajax(‘file.php)
    .success(function() { ... })
    .error(function() { ... });



// somewhere else
req.success(function() { ... });
req.error(function() { ... });
CREATE YOUR OWN
              DEFERRED
var d1 = $.Deferred(),
var d2 = $.Deferred();

$('#button1').bind('click', function() {
    d1.resolve();
});

$('#button2').bind('click', function() {
    d2.resolve();
});

$.when( d1.promise(), d2.promise() )
    .then(function() {
            alert('both buttons clicked');
        });
NEW 1.5 FEATURE:
               $.SUB()


Creates a new copy of jQuery whose properties and methods
 can be modified without affecting the original jQuery object.
$.SUB EXAMPLE


var sub = jQuery.sub();

sub.fn.bar = function(){ };

$('#foo').bar();     // no
sub('#foo').bar();   // yes
THANKS FOR LISTENING
      @mennovanslooten

More Related Content

What's hot

jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
dmethvin
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Jon Kruger
 

What's hot (20)

AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Special Events
Special EventsSpecial Events
Special Events
 
Events
EventsEvents
Events
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 

Similar to amsterdamjs - jQuery 1.5

international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
Chris Saylor
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
baygross
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
Robert Nyman
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
Remy Sharp
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
Robert Nyman
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
Robert Nyman
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
Robert Nyman
 
[removed] $file, removeRemove}, list #su.docx
[removed] $file, removeRemove}, list #su.docx[removed] $file, removeRemove}, list #su.docx
[removed] $file, removeRemove}, list #su.docx
gerardkortney
 

Similar to amsterdamjs - jQuery 1.5 (20)

jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuery
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Java script for web developer
Java script for web developerJava script for web developer
Java script for web developer
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
 
[removed] $file, removeRemove}, list #su.docx
[removed] $file, removeRemove}, list #su.docx[removed] $file, removeRemove}, list #su.docx
[removed] $file, removeRemove}, list #su.docx
 
JQuery In Drupal
JQuery In DrupalJQuery In Drupal
JQuery In Drupal
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 

amsterdamjs - jQuery 1.5

  • 1. JQUERY 1.5 amsterdamjs meetup - February 8th 2011 @mennovanslooten
  • 2. IN THIS PRESENTATION... • New features • Improvements • jQuery.sub() • jQuery.ajax() • Deferred objects • Performance
  • 4. WHO HERE USES JQUERY?
  • 5. JQUERY MICRO TUTORIAL // jQuery is... // a function you can call to query or create DOM elements: var old_element = $(‘#some > .css[selector]’); var new_element = $(‘<div id=”hello”><span>world</span></div>’);
  • 6. JQUERY MICRO TUTORIAL // This function always returns an array-like collection with // lots of convenient chain-able methods. $(‘#target’) .empty() .append(new_element);
  • 7. JQUERY MICRO TUTORIAL // attaching events some_element.bind(‘click’, function(e) { // handler code }); // triggering events some_element.trigger(‘click’);
  • 8. JQUERY MICRO TUTORIAL // custom events some_element.bind(‘whatever’, function(e) { // handler code }); // namespaced events some_element.bind(‘click.myapp’, function(e) { // handler code });
  • 9. JQUERY MICRO TUTORIAL // jQuery is also... // a collection of useful utilities (not chain-able) var a = [0, 1, 2, 3]; $.each(a, function(i, val) { alert(‘Index ‘ + i + ‘ has value ‘ + val); }); var b = $.isArray(a);
  • 10. JQUERY MICRO TUTORIAL // ajax: load directly into element $(‘#target’).load(‘file.html’); // fine-grained control $.ajax({ url : ‘file.html’, type : ‘POST’, async : false, success: function(data, status, jqXHR) { // handle response } });
  • 12. 1.5 IMPROVEMENT: AJAX • complete rewrite • implemented as a “deferred object”
  • 13. NEW 1.5 FEATURE: DEFERRED OBJECTS A deferred object is a chainable utility object that can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.
  • 14. WHAT?
  • 15. DEFERRED AJAX EXAMPLE // the old way var success; $.ajax(‘file.php’, { success : function() { success = true; }, error : function() { success = false; } }); // somewhere else if (success) { // ... } else { // .... }
  • 16. DEFERRED AJAX EXAMPLE // the new way var req = $.ajax(‘file.php) .success(function() { ... }) .error(function() { ... }); // somewhere else req.success(function() { ... }); req.error(function() { ... });
  • 17. CREATE YOUR OWN DEFERRED var d1 = $.Deferred(), var d2 = $.Deferred(); $('#button1').bind('click', function() { d1.resolve(); }); $('#button2').bind('click', function() { d2.resolve(); }); $.when( d1.promise(), d2.promise() ) .then(function() { alert('both buttons clicked'); });
  • 18. NEW 1.5 FEATURE: $.SUB() Creates a new copy of jQuery whose properties and methods can be modified without affecting the original jQuery object.
  • 19. $.SUB EXAMPLE var sub = jQuery.sub(); sub.fn.bar = function(){ }; $('#foo').bar(); // no sub('#foo').bar(); // yes
  • 20. THANKS FOR LISTENING @mennovanslooten

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n