SlideShare a Scribd company logo
JavaScript!
JavaScript v1
• Main features: handle browser events (load, mouse, etc.) and
  navigate and manipulate the web page document
• Primary original use was for image swapping on mouse events
  and basic form validation
• Browser rendering engines were too underpowered to do
  anything cool with it
• Inconsistent implementations between browsers
  • Netscape 3 (who made it) was a full version ahead of IE 3
JavaScript v1
• Most “serious” developers hated it
  •   No IDE
  •   No debugging tools
  •   Security flaws
  •   Marketed as “JavaScript for dummies”
  •   Mostly used by web designers
      copy-paste-ing code
Browser v4
• Netscape and IE 4 introduce completely separate
  implementations of Dynamic HTML / Document Object Model
• Libraries were created to make Netscape code work in IE and
  vice versa
• Lowest common denominator was too low to accomplish
  anything
Browser v4
• Two side effects:
  • Netscape died to give way to Mozilla, but it was years before
    Mozilla had a stable release, allowing IE to dominate market
    share
  • Flash was really the only consistent platform to do anything cool
My Favourite JavaScript Quote
“Anyway I know only one programming language worse than C
and that is JavaScript. [...] the net result is that the programming-
vacuum filled itself with the most horrible kluge in the history of
computing: JavaScript.”
 - Robert Cailliau
Enter AJAX
• Most devs more or less ignored JavaScript as a useful language
  until AJAX came along
• AJAX suddenly enabled great user experiences on web pages
  by loading data / html / scripts after the initial page load, not
  requiring a browser refresh between actions
• A number of cross-browser AJAX frameworks emerged that
  also enabled other cross-browser functionality
  • Prototype, jQuery, MooTools, Dojo, etc.
• Debugging tools created (firebug, dev console), better support
  in IDEs, browser rendering more powerful
• All in all, JavaScript is good now (or at least better)
JavaScript – Functions
• Functions are objects
  •   Have their own properties and methods (length, call, etc.)
  •   Can be assigned to variables
  •   Can be passed as arguments
  •   Can be returned by other functions
  •   Can be nested, maintaining scope (see: closure)
JavaScript – Objects
• Prototype-based Objects
  • Every object has a “prototype” property that references another
    object
  • Prototype is only used for retrieval
     • If our object doesn’t have the requested property, it’ll check its
       prototype (and its prototype, and its prototype, and so on…)
  • Prototypes are dynamic
     • editing a prototype means all of its objects are affected, regardless of
       when they were created
JavaScript – Literal Notation
•   Easy inline way to declare objects and arrays
•   aka JSON
•   Object: { Property: Value }
•   Array: [1, 2, 3]
•   Object Array: [{Property: Value}, {Property: Value}]
JavaScript – Scope
• Scope
  • Scope in JavaScript is controlled by Functions, not Blocks
  • Variables declared outside of a function / object (or without var)
    are automatically Global
      • Can lead to terrible conflicts between scripts
• Context (this)
  • “this” refers to the owner of the function being called
  • Anonymous functions are owned by Global (window)
  • Event handlers are owned by the control firing the event
    (sometimes)
JavaScript
• Bad Stuff
  •   Global Variables by default
  •   Lack of language-defined modules / namespaces
  •   No standard for distributing code across files
  •   Pretty small core library
  •   All numbers are binary floating points
       • Makes bitwise operators REALLY inefficient
  • NaN
       • typeof NaN === ‘number’ //true
       • NaN === NaN //false
  •   0, NaN, ‘’, false, null, and undefined all evaluate to false
  •   == behaves differently from ===
  •   No real way to “protect” source code / IP
  •   Still some browser-specific inconsistencies
       • *cough* Internet Explorer *cough*
jQuery
•   DOM selection using selector syntax
•   DOM traversal and modification
•   Event binding and delegation
•   CSS manipulation
•   AJAX
•   Extensibility
•   Cross-browser support
jQuery - Selectors
jQuery selectors are AWESOME.

Pre-jQuery                                              jQuery

var classElements = new Array();                        var classElements = $(“.happyCat”);
function getElementsByClassName(className, element) {
  if(element.className == className) {
     classElements.push(element);
  }
  for(var node in element.childNodes) {
     getElementsByClassName(
        className, node);
  }
}
getElementsByClassName(“sadPanda”,
  document.body);
jQuery - Selectors
                                                                    :last
   :animated
                   :visible       *alt=“backgroundImage”+
                                                                :even
    #playlistTable
                                      :checked
             :button                                        td.name + td.address

                              :contains(“Hello”)
   :parent                                             .className

                                              :gt(5)
    :first-child         table > tr




“#playlistTable td.name:odd > img*alt|=“chad”+:visible”
jQuery - Manipulation
• Allows reading, editing, insertion, deletion, and replication of
  elements and attributes in the document
   • $(‘#playlistTable’).append(“<div>Hello</div>”)
   • $(‘.userRow’).addClass(‘selected’);
   • $(‘#accountTable tr’).detach();
      • See also: $(‘#accountTable’).empty();
   • $(‘#errorMessage’).html(“<b>I didn’t say Simon Says</b>”);
   • $(‘#errorMessage’).css(‘color’, ‘red’);
   • $(‘#errorMessage’).css(‘color’); //returns ‘red’
   • $(‘input:text’).val(“I HAVE TAKEN OVER YOUR FORM”);
jQuery - Events
• Register functions to handle when the browser (or other code)
  triggers an event
  • $(‘input:button’).bind(‘click’, function() , alert(“CLICK.”); -);
  • $(‘div.hoverable’).delegate(‘mouseover’, handleHoverEvent);
  • $(document).ready(pageLoad);
jQuery - AJAX
• Make requests to the server for data / HTML / JavaScript
  without refreshing the page
  • get(“/products”, onProductsLoaded);
  • $(‘#widgetDialog’).load(“/widgets/editProduct”);
  • var formData = $(‘form’).serialize();
    post(“/saveProduct”, formdata, onProductSaved);
jQuery - Extensibility
• Hundreds of jQuery plugins
jQuery Templates
• Sends a template of how data should be represented with the
  page, then sends the data to fill that template with
Backbone.js
•   Client-side JavaScript MVC framework
•   Models with custom events
•   Collections with enumerable functions
•   Views with declarative event handling
•   Integrates with RESTful JSON web services
Backbone - Collections
• Represents a group of models
• Maps to a REST endpoint
  • /products
• Collection.fetch – calls REST endpoint, parses result, creates
  model objects, adds to collection
• Fires “refresh”, “add”, “remove”, “change” events
• Provides enumeration functions over models (foreach, find,
  map, max, min, sort, indexof, etc)
Backbone - Models
• Represents the data from the server as a property bag
  • Model.get(“property”), Model.set(,Property: “value”-)
• Provides methods to interact with REST service
  • Fetch, save, destroy
• Provides validation
• Fires events (“changed”)
Backbone - Views
• Represents the view of a model or a control on a page
  • More of a ViewModel than a true View
• Tied to a root element in the page (View.el)
• Responds to events on its model or collection
  • this.model.bind(‘change’, this.render);
• Declarative Events
   , “click .icon”: “open” -
• Use in conjunction with jQuery
  • this.$(‘.selector’) === $(‘.selector’, this.el)

More Related Content

KEY
Nothing Hard Baked: Designing the Inclusive Web
KEY
User Interface Development with jQuery
PPTX
Getting started with jQuery
KEY
The Inclusive Web: hands-on with HTML5 and jQuery
PPTX
A Rich Web experience with jQuery, Ajax and .NET
PDF
fuser interface-development-using-jquery
PDF
jQuery Introduction
PPTX
jQuery
Nothing Hard Baked: Designing the Inclusive Web
User Interface Development with jQuery
Getting started with jQuery
The Inclusive Web: hands-on with HTML5 and jQuery
A Rich Web experience with jQuery, Ajax and .NET
fuser interface-development-using-jquery
jQuery Introduction
jQuery

What's hot (19)

PDF
Introduction to jQuery
KEY
Week 4 - jQuery + Ajax
PPTX
A Rich Web Experience with jQuery, Ajax and .NET
PPTX
SharePoint and jQuery Essentials
PDF
D3.js and SVG
PPTX
Unobtrusive javascript with jQuery
KEY
MongoDB at ZPUGDC
PDF
JavaScript Library Overview (Ajax Exp West 2007)
PDF
Advancing JavaScript with Libraries (Yahoo Tech Talk)
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
PDF
jQuery: Nuts, Bolts and Bling
PPTX
PDF
jQuery Loves Developers - Oredev 2009
PDF
jQuery for beginners
PDF
Organizing Code with JavascriptMVC
PDF
Introduction to jQuery (Ajax Exp 2007)
PDF
bcgr3-jquery
PDF
jQuery Features to Avoid
Introduction to jQuery
Week 4 - jQuery + Ajax
A Rich Web Experience with jQuery, Ajax and .NET
SharePoint and jQuery Essentials
D3.js and SVG
Unobtrusive javascript with jQuery
MongoDB at ZPUGDC
JavaScript Library Overview (Ajax Exp West 2007)
Advancing JavaScript with Libraries (Yahoo Tech Talk)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery: Nuts, Bolts and Bling
jQuery Loves Developers - Oredev 2009
jQuery for beginners
Organizing Code with JavascriptMVC
Introduction to jQuery (Ajax Exp 2007)
bcgr3-jquery
jQuery Features to Avoid
Ad

Viewers also liked (6)

PPTX
What The F#
PPTX
Total Engagement
PPTX
Node.js
PPTX
Give your web apps some backbone
PPTX
Reactive Extensions
PPTX
Single page apps and the web of tomorrow
What The F#
Total Engagement
Node.js
Give your web apps some backbone
Reactive Extensions
Single page apps and the web of tomorrow
Ad

Similar to JavaScript! (20)

PPTX
Jquery fundamentals
PPTX
Jquery
PDF
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
PPT
Learn javascript easy steps
PDF
bcgr3-jquery
PPTX
Learning About JavaScript (…and its little buddy, JQuery!)
PPTX
Introduction to JavaScript
PPT
jQuery Objects
PDF
Awesome html with ujs, jQuery and coffeescript
PPT
Easy javascript
KEY
PPTX
Tips for writing Javascript for Drupal
PPTX
JS Essence
PPTX
SPTechCon - Share point and jquery essentials
KEY
[Coscup 2012] JavascriptMVC
PPT
J query presentation
PPT
J query presentation
PPTX
Jqueryppt (1)
PPTX
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
PPT
J query
Jquery fundamentals
Jquery
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Learn javascript easy steps
bcgr3-jquery
Learning About JavaScript (…and its little buddy, JQuery!)
Introduction to JavaScript
jQuery Objects
Awesome html with ujs, jQuery and coffeescript
Easy javascript
Tips for writing Javascript for Drupal
JS Essence
SPTechCon - Share point and jquery essentials
[Coscup 2012] JavascriptMVC
J query presentation
J query presentation
Jqueryppt (1)
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
J query

More from RTigger (14)

PPTX
You Can't Buy Agile
PPTX
Caching up is hard to do: Improving your Web Services' Performance
PPTX
Ready, set, go! An introduction to the Go programming language
PPTX
Open source web services
PPTX
How to hire a hacker
PPTX
Windows 8 programming with html and java script
PPTX
Open regina
PPTX
Async in .NET
PPTX
Hackers, hackathons, and you
PPTX
AJAX, JSON, and Client-Side Templates
PPTX
Parallel Processing
PPTX
Sql vs NoSQL
PPTX
Git’in Jiggy With Git
PPTX
Web Services
You Can't Buy Agile
Caching up is hard to do: Improving your Web Services' Performance
Ready, set, go! An introduction to the Go programming language
Open source web services
How to hire a hacker
Windows 8 programming with html and java script
Open regina
Async in .NET
Hackers, hackathons, and you
AJAX, JSON, and Client-Side Templates
Parallel Processing
Sql vs NoSQL
Git’in Jiggy With Git
Web Services

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Electronic commerce courselecture one. Pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The AUB Centre for AI in Media Proposal.docx
Understanding_Digital_Forensics_Presentation.pptx
Programs and apps: productivity, graphics, security and other tools
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Machine learning based COVID-19 study performance prediction
Electronic commerce courselecture one. Pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks

JavaScript!

  • 2. JavaScript v1 • Main features: handle browser events (load, mouse, etc.) and navigate and manipulate the web page document • Primary original use was for image swapping on mouse events and basic form validation • Browser rendering engines were too underpowered to do anything cool with it • Inconsistent implementations between browsers • Netscape 3 (who made it) was a full version ahead of IE 3
  • 3. JavaScript v1 • Most “serious” developers hated it • No IDE • No debugging tools • Security flaws • Marketed as “JavaScript for dummies” • Mostly used by web designers copy-paste-ing code
  • 4. Browser v4 • Netscape and IE 4 introduce completely separate implementations of Dynamic HTML / Document Object Model • Libraries were created to make Netscape code work in IE and vice versa • Lowest common denominator was too low to accomplish anything
  • 5. Browser v4 • Two side effects: • Netscape died to give way to Mozilla, but it was years before Mozilla had a stable release, allowing IE to dominate market share • Flash was really the only consistent platform to do anything cool
  • 6. My Favourite JavaScript Quote “Anyway I know only one programming language worse than C and that is JavaScript. [...] the net result is that the programming- vacuum filled itself with the most horrible kluge in the history of computing: JavaScript.” - Robert Cailliau
  • 7. Enter AJAX • Most devs more or less ignored JavaScript as a useful language until AJAX came along • AJAX suddenly enabled great user experiences on web pages by loading data / html / scripts after the initial page load, not requiring a browser refresh between actions • A number of cross-browser AJAX frameworks emerged that also enabled other cross-browser functionality • Prototype, jQuery, MooTools, Dojo, etc. • Debugging tools created (firebug, dev console), better support in IDEs, browser rendering more powerful • All in all, JavaScript is good now (or at least better)
  • 8. JavaScript – Functions • Functions are objects • Have their own properties and methods (length, call, etc.) • Can be assigned to variables • Can be passed as arguments • Can be returned by other functions • Can be nested, maintaining scope (see: closure)
  • 9. JavaScript – Objects • Prototype-based Objects • Every object has a “prototype” property that references another object • Prototype is only used for retrieval • If our object doesn’t have the requested property, it’ll check its prototype (and its prototype, and its prototype, and so on…) • Prototypes are dynamic • editing a prototype means all of its objects are affected, regardless of when they were created
  • 10. JavaScript – Literal Notation • Easy inline way to declare objects and arrays • aka JSON • Object: { Property: Value } • Array: [1, 2, 3] • Object Array: [{Property: Value}, {Property: Value}]
  • 11. JavaScript – Scope • Scope • Scope in JavaScript is controlled by Functions, not Blocks • Variables declared outside of a function / object (or without var) are automatically Global • Can lead to terrible conflicts between scripts • Context (this) • “this” refers to the owner of the function being called • Anonymous functions are owned by Global (window) • Event handlers are owned by the control firing the event (sometimes)
  • 12. JavaScript • Bad Stuff • Global Variables by default • Lack of language-defined modules / namespaces • No standard for distributing code across files • Pretty small core library • All numbers are binary floating points • Makes bitwise operators REALLY inefficient • NaN • typeof NaN === ‘number’ //true • NaN === NaN //false • 0, NaN, ‘’, false, null, and undefined all evaluate to false • == behaves differently from === • No real way to “protect” source code / IP • Still some browser-specific inconsistencies • *cough* Internet Explorer *cough*
  • 13. jQuery • DOM selection using selector syntax • DOM traversal and modification • Event binding and delegation • CSS manipulation • AJAX • Extensibility • Cross-browser support
  • 14. jQuery - Selectors jQuery selectors are AWESOME. Pre-jQuery jQuery var classElements = new Array(); var classElements = $(“.happyCat”); function getElementsByClassName(className, element) { if(element.className == className) { classElements.push(element); } for(var node in element.childNodes) { getElementsByClassName( className, node); } } getElementsByClassName(“sadPanda”, document.body);
  • 15. jQuery - Selectors :last :animated :visible *alt=“backgroundImage”+ :even #playlistTable :checked :button td.name + td.address :contains(“Hello”) :parent .className :gt(5) :first-child table > tr “#playlistTable td.name:odd > img*alt|=“chad”+:visible”
  • 16. jQuery - Manipulation • Allows reading, editing, insertion, deletion, and replication of elements and attributes in the document • $(‘#playlistTable’).append(“<div>Hello</div>”) • $(‘.userRow’).addClass(‘selected’); • $(‘#accountTable tr’).detach(); • See also: $(‘#accountTable’).empty(); • $(‘#errorMessage’).html(“<b>I didn’t say Simon Says</b>”); • $(‘#errorMessage’).css(‘color’, ‘red’); • $(‘#errorMessage’).css(‘color’); //returns ‘red’ • $(‘input:text’).val(“I HAVE TAKEN OVER YOUR FORM”);
  • 17. jQuery - Events • Register functions to handle when the browser (or other code) triggers an event • $(‘input:button’).bind(‘click’, function() , alert(“CLICK.”); -); • $(‘div.hoverable’).delegate(‘mouseover’, handleHoverEvent); • $(document).ready(pageLoad);
  • 18. jQuery - AJAX • Make requests to the server for data / HTML / JavaScript without refreshing the page • get(“/products”, onProductsLoaded); • $(‘#widgetDialog’).load(“/widgets/editProduct”); • var formData = $(‘form’).serialize(); post(“/saveProduct”, formdata, onProductSaved);
  • 19. jQuery - Extensibility • Hundreds of jQuery plugins
  • 20. jQuery Templates • Sends a template of how data should be represented with the page, then sends the data to fill that template with
  • 21. Backbone.js • Client-side JavaScript MVC framework • Models with custom events • Collections with enumerable functions • Views with declarative event handling • Integrates with RESTful JSON web services
  • 22. Backbone - Collections • Represents a group of models • Maps to a REST endpoint • /products • Collection.fetch – calls REST endpoint, parses result, creates model objects, adds to collection • Fires “refresh”, “add”, “remove”, “change” events • Provides enumeration functions over models (foreach, find, map, max, min, sort, indexof, etc)
  • 23. Backbone - Models • Represents the data from the server as a property bag • Model.get(“property”), Model.set(,Property: “value”-) • Provides methods to interact with REST service • Fetch, save, destroy • Provides validation • Fires events (“changed”)
  • 24. Backbone - Views • Represents the view of a model or a control on a page • More of a ViewModel than a true View • Tied to a root element in the page (View.el) • Responds to events on its model or collection • this.model.bind(‘change’, this.render); • Declarative Events , “click .icon”: “open” - • Use in conjunction with jQuery • this.$(‘.selector’) === $(‘.selector’, this.el)