SlideShare une entreprise Scribd logo
1  sur  15
JavaScript and jQuery,
the Atlassian way
Quick Intro
• Not a Toy language
• Small but powerful
• Has design flaws
• Hits the high notes
Key Concepts
• Load and Go
• Loose Typing
• Lambda
• Prototypal Inheritance
• Single Threaded
Values
• Numbers
– 64-bit floating point, NaN, Infinity

• Strings
– UCS-2 (not quite UTF-16), Immutable

• Booleans
• Objects
– Hashes

• null
• undefined
Resources
http://api.jquery.com/
https://developer.mozilla.org/en/JavaScripthttp://document
cloud.github.com/backbone/
http://documentcloud.github.com/underscore/
// Collections!
var $collection = jQuery("a[rel=userprofile]");
// $collection is a jQuery collection.
// It can have 0 or more elements.
$collection.addClass("foo");
// API functions apply to all elements in the
// collection.
var p = document.getElementById("myUserProfile");
var $collection2 = jQuery(p);
// $collection2 is a jQuery collection.
// It has 1 element.
var $hi = jQuery("<p>Hello, world.</p>");
// $hi is also a jQuery collection,
// containing 1 element.
console.log($collection.length);
// The number of elements in $collection.
console.log($collection[0]);
// The first DOM element in $collection.
//methods on the same collection
$collection.attr("hreflang", "fr");
// Sets the "hreflang" attribute on *all*
// elements in $collection.
$collection.attr("href");
// Gets the "href" attribute of the
// *first* element in $collection.
//script execution and DOM Ready
console.log(
jQuery("input[type=checkbox]").length
); // => 0
// The page has only loaded enough
// elements to get to this <script>.
jQuery(function() {
// This function is called when the page
// has fully loaded.
console.log(
jQuery("input[type=checkbox]").length
); // => 6
});
//events
function handleEvent(event) {
console.log(this);
// The element clicked,
// not a jQuery collection
event.preventDefault();
// Prevent the default action of this
// event.
}
$collection.bind("click", handleEvent);
// handleEvent is called when any element
// in $collection is clicked.
$collection.unbind("click", handleEvent);
//when I say stop I mean…
$collection.bind("keydown",
function(event) {
event.stopPropagation();
event.stopImmediatePropagation();
return false;
// Avoid these.
// This breaks the key rule that
// event handlers should be agnostic
// of other event handlers.
});
//custom events
$collection.bind("myCustomEvent",
function(event) {
// custom event handler
});
$collection.trigger("myCustomEvent");
// Dispatch an event of type
// "myCustomEvent"
//bind to arbitrary objects
MyApp.ISSUES = {};
jQuery(MyApp.ISSUES).bind("add_issue",
function(newIssue) {
// Handle adding new issues
});
// jQuery(MyApp.ISSUES) is a jQuery
// collection containing the JavaScript
// object MyApp.ISSUES.
var newIssue = new Issue(newIssueId);
jQuery(MyApp.ISSUES).trigger("add_issue",
[newIssue]);
// The second argument to trigger() is an
// array of arguments to supply listeners.
//ajax
var xhr = jQuery.ajax("/users", {
type: "PUT", // HTTP method
contentType: "application/json", // request header
data: '{"name":"Fred Jones","role":"JavaScript Developer"}',
dataType: "json" // Accept: application/json
});
xhr.complete(function(xhr) {
console.log(xhr.status); // 200
console.log(xhr.data); // JSON-decoded response
console.log(xhr.responseText); // JSON string
});
xhr.success(function(data) {
console.log(data); // JSON-decoded response
});
xhr.error(function(xhr, errType) {
console.log(errType); // "error" (4xx or 5xx)
// Other possible values: "abort", "timeout", "parsererror"
});
//store data against DOM nodes
// Set data:
jQuery.data(obj, "key", "value");
// Get data:
jQuery.data(obj, "key"); // => "value"
//
//
//
//

obj can be any DOM element or
JavaScript object.
The key can be any string.
The value can be any type.

Contenu connexe

Tendances

Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIsDécouplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Nicolas Blanco
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
Jussi Pohjolainen
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
baygross
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
dmethvin
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
Luke Summerfield
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
Jarod Ferguson
 
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
girish82
 

Tendances (20)

Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIsDécouplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
 
So long, jQuery, and thanks for all the fish!
So long, jQuery, and thanks for all the fish!So long, jQuery, and thanks for all the fish!
So long, jQuery, and thanks for all the fish!
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
JQuery
JQueryJQuery
JQuery
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
php Slideshare
php Slidesharephp Slideshare
php Slideshare
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDart
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
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
 

En vedette

Statistical supplement june 2011 final[1]
Statistical supplement june 2011   final[1]Statistical supplement june 2011   final[1]
Statistical supplement june 2011 final[1]
Sammit Shukla
 

En vedette (9)

Evented Javascript
Evented JavascriptEvented Javascript
Evented Javascript
 
Młodzi 2011 - Berlin 2012
Młodzi 2011 - Berlin 2012Młodzi 2011 - Berlin 2012
Młodzi 2011 - Berlin 2012
 
Summit 2013 - Integrations at Atlassian
Summit 2013 - Integrations at AtlassianSummit 2013 - Integrations at Atlassian
Summit 2013 - Integrations at Atlassian
 
HAMMERTIME EXAM REVIEW
HAMMERTIME EXAM REVIEWHAMMERTIME EXAM REVIEW
HAMMERTIME EXAM REVIEW
 
Młodzi 2011 - Mielec - 21 września 2012
Młodzi 2011 - Mielec - 21 września 2012Młodzi 2011 - Mielec - 21 września 2012
Młodzi 2011 - Mielec - 21 września 2012
 
Jak naprawić klin podatkowy - Polityka Insight
Jak naprawić klin podatkowy - Polityka InsightJak naprawić klin podatkowy - Polityka Insight
Jak naprawić klin podatkowy - Polityka Insight
 
Summit 2012 - How Atlassian Uses Confluence
Summit 2012 - How Atlassian Uses ConfluenceSummit 2012 - How Atlassian Uses Confluence
Summit 2012 - How Atlassian Uses Confluence
 
Statistical supplement june 2011 final[1]
Statistical supplement june 2011   final[1]Statistical supplement june 2011   final[1]
Statistical supplement june 2011 final[1]
 
Export Marketing services in India
Export Marketing services in IndiaExport Marketing services in India
Export Marketing services in India
 

Similaire à Javascript and jQuery intro

fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
Kostas Mavridis
 
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
 

Similaire à Javascript and jQuery intro (20)

06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
 
jQuery
jQueryjQuery
jQuery
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
 
Modular and Event-Driven JavaScript
Modular and Event-Driven JavaScriptModular and Event-Driven JavaScript
Modular and Event-Driven JavaScript
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
DrupalCon jQuery
DrupalCon jQueryDrupalCon jQuery
DrupalCon 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
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuery
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
"this" in JavaScript
"this" in JavaScript"this" in JavaScript
"this" in JavaScript
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
JQuery In Drupal
JQuery In DrupalJQuery In Drupal
JQuery In Drupal
 
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
 

Dernier

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 

Javascript and jQuery intro

  • 2. Quick Intro • Not a Toy language • Small but powerful • Has design flaws • Hits the high notes
  • 3. Key Concepts • Load and Go • Loose Typing • Lambda • Prototypal Inheritance • Single Threaded
  • 4. Values • Numbers – 64-bit floating point, NaN, Infinity • Strings – UCS-2 (not quite UTF-16), Immutable • Booleans • Objects – Hashes • null • undefined
  • 6. // Collections! var $collection = jQuery("a[rel=userprofile]"); // $collection is a jQuery collection. // It can have 0 or more elements. $collection.addClass("foo"); // API functions apply to all elements in the // collection. var p = document.getElementById("myUserProfile"); var $collection2 = jQuery(p); // $collection2 is a jQuery collection. // It has 1 element.
  • 7. var $hi = jQuery("<p>Hello, world.</p>"); // $hi is also a jQuery collection, // containing 1 element. console.log($collection.length); // The number of elements in $collection. console.log($collection[0]); // The first DOM element in $collection.
  • 8. //methods on the same collection $collection.attr("hreflang", "fr"); // Sets the "hreflang" attribute on *all* // elements in $collection. $collection.attr("href"); // Gets the "href" attribute of the // *first* element in $collection.
  • 9. //script execution and DOM Ready console.log( jQuery("input[type=checkbox]").length ); // => 0 // The page has only loaded enough // elements to get to this <script>. jQuery(function() { // This function is called when the page // has fully loaded. console.log( jQuery("input[type=checkbox]").length ); // => 6 });
  • 10. //events function handleEvent(event) { console.log(this); // The element clicked, // not a jQuery collection event.preventDefault(); // Prevent the default action of this // event. } $collection.bind("click", handleEvent); // handleEvent is called when any element // in $collection is clicked. $collection.unbind("click", handleEvent);
  • 11. //when I say stop I mean… $collection.bind("keydown", function(event) { event.stopPropagation(); event.stopImmediatePropagation(); return false; // Avoid these. // This breaks the key rule that // event handlers should be agnostic // of other event handlers. });
  • 12. //custom events $collection.bind("myCustomEvent", function(event) { // custom event handler }); $collection.trigger("myCustomEvent"); // Dispatch an event of type // "myCustomEvent"
  • 13. //bind to arbitrary objects MyApp.ISSUES = {}; jQuery(MyApp.ISSUES).bind("add_issue", function(newIssue) { // Handle adding new issues }); // jQuery(MyApp.ISSUES) is a jQuery // collection containing the JavaScript // object MyApp.ISSUES. var newIssue = new Issue(newIssueId); jQuery(MyApp.ISSUES).trigger("add_issue", [newIssue]); // The second argument to trigger() is an // array of arguments to supply listeners.
  • 14. //ajax var xhr = jQuery.ajax("/users", { type: "PUT", // HTTP method contentType: "application/json", // request header data: '{"name":"Fred Jones","role":"JavaScript Developer"}', dataType: "json" // Accept: application/json }); xhr.complete(function(xhr) { console.log(xhr.status); // 200 console.log(xhr.data); // JSON-decoded response console.log(xhr.responseText); // JSON string }); xhr.success(function(data) { console.log(data); // JSON-decoded response }); xhr.error(function(xhr, errType) { console.log(errType); // "error" (4xx or 5xx) // Other possible values: "abort", "timeout", "parsererror" });
  • 15. //store data against DOM nodes // Set data: jQuery.data(obj, "key", "value"); // Get data: jQuery.data(obj, "key"); // => "value" // // // // obj can be any DOM element or JavaScript object. The key can be any string. The value can be any type.