SlideShare une entreprise Scribd logo
1  sur  52
JavaScript 101
                      Sven Lito - Front-end Developer
                 slito@tagworldwide.com + @svenlito + http://svenlito.com




Friday, 13 May 2011
Friday, 13 May 2011
What is JavaScript ?




Friday, 13 May 2011
JavaScript:
           ★          Created by Brendan Eich 1995
           ★          Developed in less than 2 Weeks
           ★          First release in NetScape 2
           ★          Influenced by Scheme,Java,Self
           ★          Interpreted language
           ★          Object-Oriented



Friday, 13 May 2011
What it’s not..




Friday, 13 May 2011
JavaScript




                                               jQuery
      probs to: rebecca murphey


Friday, 13 May 2011
Friday, 13 May 2011
JavaScript Basics




Friday, 13 May 2011
Variable Declaration:


             var arnoldSchwarzenegger = "Actor",
                 isNiceGuy = false;




Friday, 13 May 2011
Function Declaration:

                      function arniQuote() {
                         return "I'll be back.";
                      };




Friday, 13 May 2011
function makeMovie(withLindaHamilton) {
             var rad = withLindaHamilton || false;
          };




Friday, 13 May 2011
isGovernor ? "Cool Dude" : "No? Awww..";




Friday, 13 May 2011
Comparison Operators




Friday, 13 May 2011
★ = Assignment

                      ★ == Equality

                      ★ === Identity




Friday, 13 May 2011
// Assignment
                var bestFriend = "T1000";


                // Equality
                if (5 == "5") {
                  //true
                }


                // Identity
                if (5 === "5") {
                  //false
                }


Friday, 13 May 2011
// Short-circuit logic
                if (true || false)

                if (false && true)

                // Makes this code safe
                if (obj && obj.property)



Friday, 13 May 2011
Typecasting, baby!
                      "..changing an entity of one data type into another."




Friday, 13 May 2011
// true
                5 == "5"

                // "123"
                "1" + 2 + 3;




Friday, 13 May 2011
// 6, manual type conversion
                parseInt("1", 10) + 2 + 3;

                      parseInt: Parses a string argument and returns an
                           integer of the specified radix or base.




Friday, 13 May 2011
JavaScript data types




Friday, 13 May 2011
Primitive data types:

                      ★   Undefined

                      ★   Null

                      ★   Boolean

                      ★   Number

                      ★   String

                      ★   object



Friday, 13 May 2011
Primitive data types:

                      ★   Undefined

                      ★   Null

                      ★   Boolean

                      ★   Number

                      ★   String

                      ★   object << not this guy



Friday, 13 May 2011
Primitive data types:

                      ★   Undefined

                      ★   Null

                      ★   Boolean

                      ★   Number

                      ★   String

                      ★   object      Hi, I’m
                                      smart..



Friday, 13 May 2011
"Everything in JavaScript
                      acts like an object, with
                      the only two exceptions
                      being null and undefined."

                              - Arnold Schwarzenegger




Friday, 13 May 2011
Type checking



Friday, 13 May 2011
typeof return values:
                      ★   string

                      ★   number

                      ★   boolean

                      ★   function

                      ★   object

                      ★   undefined


Friday, 13 May 2011
typeof fanClub // "undefined"

                var title = "Conan the Barbarian";
                typeof title // Equals "string"

                var age = 64;
                typeof age // Equals "number"




Friday, 13 May 2011
function anotherQuote() {
            return "If it bleeds, we can kill it.";
          }

          typeof anotherQuote; // "function"




Friday, 13 May 2011
var obj = {};
       typeof obj // "object"

       var arr = ["A", "R", "N", "O", "L", "D"];
       typeof arr // "object"




Friday, 13 May 2011
var obj = {};
       typeof obj // "object"

       var arr = ["A", "R", "N", "O", "L", "D"];
       typeof arr // "object"
                                   Blimey!




Friday, 13 May 2011
using instanceof



Friday, 13 May 2011
obj instanceof Array // false
         arr instanceof Array // true




Friday, 13 May 2011
Functions


Friday, 13 May 2011
procedural


                function notAHit() {
                  return "Stay Hungry";
                }




Friday, 13 May 2011
Functions as variables

           var wroteScript = function () {
              return "The 6th Day";
           };

           wroteScript();




Friday, 13 May 2011
Anonymous

         $('#conan').bind('click', function (e) {
           alert("some string");
         });



                      I’m in your jQuery’s binding yo clicks..




Friday, 13 May 2011
Immediately-Invoked
                      Function Expression
                            (IIFE)

                (function() {
                  var judgmentDay = "Shot in 1991";
                  return judgmentDay;
                })();




Friday, 13 May 2011
(function() {
                  var judgmentDay = "Shot in 1991";
                  return judgmentDay;
                })();




                      Invocation operator



Friday, 13 May 2011
Function arguments




Friday, 13 May 2011
★ the arguments collection

                      ★ Property: arguments.length

                      ★ NOT an array   (array-like object)




Friday, 13 May 2011
function sum(a, b, c) {
                        return a + b + c;
                      }

                      sum(1, 2, 3); // 6
                      sum(1, 2); // NaN




Friday, 13 May 2011
function sum() {
                  var sum = 0,
                      l = arguments.length,
                      i = 0;

                      for (i; i < l; i++) {
                        sum += arguments[i];
                      }
                      return sum;
                }

                sum(1, 2, 3); // 6
                sum(1, 2); // 3
                sum(1, 2, 7, 11, 5); // 26


Friday, 13 May 2011
Objects



Friday, 13 May 2011
Object literal

                      var arnold = {
                         name : "Arnold Schwarzenegger",
                         gotAnOscar : true
                      };

                      alert(arnold.name);   // "Arnold Schwarzenegger"




Friday, 13 May 2011
Object notation

                       arnold["arms"] = 2;
                       arnold.arms = 2;



                       did you just say array?



Friday, 13 May 2011
Object notation

                          arnold["arms"] = 2;
                          arnold.arms = 2;



                      Same thing, different syntax



Friday, 13 May 2011
works with any object


                      var arnold = {};

                      arnold[1972] = "Year of birth";
                      arnold["born"] = 1972;
                      arnold[true] = false;




Friday, 13 May 2011
var decentMovie = {
        title : "Red Sonia",
        year : 1997
     };

     for (var item in decentMovie) {
       /*
          make sure we only check decentMovie
          and not the whole prototype chain
       */
       if (decentMovie.hasOwnProperty(item)) {
          alert(item + ": " + decentMovie[item]);
       }
     }


Friday, 13 May 2011
Arni aside, srsly.
                      How do I use all of
                      this in real life?



Friday, 13 May 2011
// TAG namespace
                TAG = window.TAG || {};

                var TAG = (function ($) {

                      // private vars
                      var
                        privateVar1 = $('#boo-selecta'),
                        privateVar2 = $('#braaap'),
                        badAssArray = [];

                      return {
                         // approvals module
                         approvals: {
                           methodCall1: function (jQuery, TAG) {
                             alert("some string");
                           }
                         }
                      };

                })(jQuery);

                TAG.approvals.methodCall1(); // "some string"
Friday, 13 May 2011
Questions??



Friday, 13 May 2011
Thanks!


    email: slito@tagworldwide.com
    twitter: @svenlito


Friday, 13 May 2011

Contenu connexe

Similaire à JavaScript 101

JavaScript por debaixo dos panos
JavaScript por debaixo dos panosJavaScript por debaixo dos panos
JavaScript por debaixo dos panosDouglas Campos
 
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with MagentoMagento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magentovarien
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagentoImagine
 
Javascript - How to avoid the bad parts
Javascript - How to avoid the bad partsJavascript - How to avoid the bad parts
Javascript - How to avoid the bad partsMikko Ohtamaa
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackabilityPuppet
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPsmueller_sandsmedia
 

Similaire à JavaScript 101 (8)

Testable Javascript
Testable JavascriptTestable Javascript
Testable Javascript
 
JavaScript por debaixo dos panos
JavaScript por debaixo dos panosJavaScript por debaixo dos panos
JavaScript por debaixo dos panos
 
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with MagentoMagento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
 
Scala 101-bcndevcon
Scala 101-bcndevconScala 101-bcndevcon
Scala 101-bcndevcon
 
Javascript - How to avoid the bad parts
Javascript - How to avoid the bad partsJavascript - How to avoid the bad parts
Javascript - How to avoid the bad parts
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackability
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 

Dernier

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.pptxRustici Software
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
"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 ...Zilliz
 
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...DianaGray10
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
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 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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...Jeffrey Haguewood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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...Martijn de Jong
 
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, ...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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 FMESafe Software
 
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.pdfsudhanshuwaghmare1
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 

Dernier (20)

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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
"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 ...
 
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...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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 - 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, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

JavaScript 101

  • 1. JavaScript 101 Sven Lito - Front-end Developer slito@tagworldwide.com + @svenlito + http://svenlito.com Friday, 13 May 2011
  • 3. What is JavaScript ? Friday, 13 May 2011
  • 4. JavaScript: ★ Created by Brendan Eich 1995 ★ Developed in less than 2 Weeks ★ First release in NetScape 2 ★ Influenced by Scheme,Java,Self ★ Interpreted language ★ Object-Oriented Friday, 13 May 2011
  • 6. JavaScript jQuery probs to: rebecca murphey Friday, 13 May 2011
  • 9. Variable Declaration: var arnoldSchwarzenegger = "Actor", isNiceGuy = false; Friday, 13 May 2011
  • 10. Function Declaration: function arniQuote() { return "I'll be back."; }; Friday, 13 May 2011
  • 11. function makeMovie(withLindaHamilton) { var rad = withLindaHamilton || false; }; Friday, 13 May 2011
  • 12. isGovernor ? "Cool Dude" : "No? Awww.."; Friday, 13 May 2011
  • 14. ★ = Assignment ★ == Equality ★ === Identity Friday, 13 May 2011
  • 15. // Assignment var bestFriend = "T1000"; // Equality if (5 == "5") { //true } // Identity if (5 === "5") { //false } Friday, 13 May 2011
  • 16. // Short-circuit logic if (true || false) if (false && true) // Makes this code safe if (obj && obj.property) Friday, 13 May 2011
  • 17. Typecasting, baby! "..changing an entity of one data type into another." Friday, 13 May 2011
  • 18. // true 5 == "5" // "123" "1" + 2 + 3; Friday, 13 May 2011
  • 19. // 6, manual type conversion parseInt("1", 10) + 2 + 3; parseInt: Parses a string argument and returns an integer of the specified radix or base. Friday, 13 May 2011
  • 21. Primitive data types: ★ Undefined ★ Null ★ Boolean ★ Number ★ String ★ object Friday, 13 May 2011
  • 22. Primitive data types: ★ Undefined ★ Null ★ Boolean ★ Number ★ String ★ object << not this guy Friday, 13 May 2011
  • 23. Primitive data types: ★ Undefined ★ Null ★ Boolean ★ Number ★ String ★ object Hi, I’m smart.. Friday, 13 May 2011
  • 24. "Everything in JavaScript acts like an object, with the only two exceptions being null and undefined." - Arnold Schwarzenegger Friday, 13 May 2011
  • 26. typeof return values: ★ string ★ number ★ boolean ★ function ★ object ★ undefined Friday, 13 May 2011
  • 27. typeof fanClub // "undefined" var title = "Conan the Barbarian"; typeof title // Equals "string" var age = 64; typeof age // Equals "number" Friday, 13 May 2011
  • 28. function anotherQuote() { return "If it bleeds, we can kill it."; } typeof anotherQuote; // "function" Friday, 13 May 2011
  • 29. var obj = {}; typeof obj // "object" var arr = ["A", "R", "N", "O", "L", "D"]; typeof arr // "object" Friday, 13 May 2011
  • 30. var obj = {}; typeof obj // "object" var arr = ["A", "R", "N", "O", "L", "D"]; typeof arr // "object" Blimey! Friday, 13 May 2011
  • 32. obj instanceof Array // false arr instanceof Array // true Friday, 13 May 2011
  • 34. procedural function notAHit() { return "Stay Hungry"; } Friday, 13 May 2011
  • 35. Functions as variables var wroteScript = function () { return "The 6th Day"; }; wroteScript(); Friday, 13 May 2011
  • 36. Anonymous $('#conan').bind('click', function (e) { alert("some string"); }); I’m in your jQuery’s binding yo clicks.. Friday, 13 May 2011
  • 37. Immediately-Invoked Function Expression (IIFE) (function() { var judgmentDay = "Shot in 1991"; return judgmentDay; })(); Friday, 13 May 2011
  • 38. (function() { var judgmentDay = "Shot in 1991"; return judgmentDay; })(); Invocation operator Friday, 13 May 2011
  • 40. ★ the arguments collection ★ Property: arguments.length ★ NOT an array (array-like object) Friday, 13 May 2011
  • 41. function sum(a, b, c) { return a + b + c; } sum(1, 2, 3); // 6 sum(1, 2); // NaN Friday, 13 May 2011
  • 42. function sum() { var sum = 0, l = arguments.length, i = 0; for (i; i < l; i++) { sum += arguments[i]; } return sum; } sum(1, 2, 3); // 6 sum(1, 2); // 3 sum(1, 2, 7, 11, 5); // 26 Friday, 13 May 2011
  • 44. Object literal var arnold = { name : "Arnold Schwarzenegger", gotAnOscar : true }; alert(arnold.name); // "Arnold Schwarzenegger" Friday, 13 May 2011
  • 45. Object notation arnold["arms"] = 2; arnold.arms = 2; did you just say array? Friday, 13 May 2011
  • 46. Object notation arnold["arms"] = 2; arnold.arms = 2; Same thing, different syntax Friday, 13 May 2011
  • 47. works with any object var arnold = {}; arnold[1972] = "Year of birth"; arnold["born"] = 1972; arnold[true] = false; Friday, 13 May 2011
  • 48. var decentMovie = { title : "Red Sonia", year : 1997 }; for (var item in decentMovie) { /* make sure we only check decentMovie and not the whole prototype chain */ if (decentMovie.hasOwnProperty(item)) { alert(item + ": " + decentMovie[item]); } } Friday, 13 May 2011
  • 49. Arni aside, srsly. How do I use all of this in real life? Friday, 13 May 2011
  • 50. // TAG namespace TAG = window.TAG || {}; var TAG = (function ($) { // private vars var privateVar1 = $('#boo-selecta'), privateVar2 = $('#braaap'), badAssArray = []; return { // approvals module approvals: { methodCall1: function (jQuery, TAG) { alert("some string"); } } }; })(jQuery); TAG.approvals.methodCall1(); // "some string" Friday, 13 May 2011
  • 52. Thanks! email: slito@tagworldwide.com twitter: @svenlito Friday, 13 May 2011