SlideShare uma empresa Scribd logo
1 de 20
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.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

Notas do Editor

  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