SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
JAVASCRIPT: THE
            IMPORTANT BITS
REVIEWING JAVASCRIPT AND JQUERY FUNDAMENTALS AS WELL AS A BRIEF
                        INTRO TO NODEJS
                  Chris Saylor ( @cjsaylor ) from Zumba Fitness ®
THINK YOU KNOW JAVASCRIPT?
     typeof [] === "array"; false
     0.1 + 0.2 === 0.3; false
     a === null; false
     0 == '0'; true
     1 == '1'; true
     '' == '0'; false
     '' == 0; true
     'false' == false; false

          True or false?
THINK YOU KNOW JAVASCRIPT?
rtr
 eun
{
  a "el"
   : hlo
}



             What does this return?
THINK YOU KNOW JAVASCRIPT?
LET'S GET STARTED WITH THE BASICS.
VARIABLES
When declairing a variable without the "var", it puts the variable in
             global space which can be problematic.


  fnto hlo){
   ucin el(
    ts1='el'
     et   hlo;   / goa soe
                  / lbl cp
    vrts2='el2; / ti fnto soe
     a et   hlo'  / hs ucin cp
  }

  hlo)
   el(;

  cnoelgts1;/ 'el'
   osl.o(et) / hlo;
  cnoelgts2;/ udfnd
   osl.o(et) / neie
SCOPING
     There is no block scoping, only function scoping:
fr(a i=0 i<1;i+ {
 o  vr   ;  0 +)
  cnoelgi;
   osl.o()
}
cnoelgi;/ pit 1
 osl.o() / rns 0



     If you want to block the scope of the above loop:
(ucin( {
 fnto   )
  fr(a i=0 i<1;i+ {
   o vr    ;  0 +)
    cnoelgi;
     osl.o()
  }
});
 ()
vri
 a   ;
cnoelgi;/ udfnd
 osl.o() / neie
SCOPE IN CALLBACKS
In callbacks, you can share variables from the parent function:
vroj={
 a   b
  ojau:'el'
   bVle hlo,
  ts:fnto( {
   et    ucin)
    vrsl =ti;
     a   ef  hs
      stieu(ucin){
       eTmotfnto(
        cnoelgti.bVle;/ udfnd
         osl.o(hsojau) / neie
        cnoelgsl.bVle;/ 'el'
         osl.o(efojau) / hlo
      } 1)
       , 0;
  }
}
OBJECTS AND "CLASSES"
Objects are like JSON with some class aspects known as prototypes.
OBJECTS AND "CLASSES"
                 An example class:


Aia =(ucin){
 nml  fnto(

 fnto Aia(ae {
  ucin nmlnm)
   ti.ae=nm;
    hsnm  ae
 }

 Aia.rttp.oe=fnto( {
  nmlpooyemv    ucin)
   rtr aetti.ae+'mvd';
    eun lr(hsnm    oe.)
 };

 rtr Aia;
  eun nml

});
 ()
COMMON JAVASCRIPT PATTERNS
IMMEDIATE EXECUTION FUNCTION
(ucin){
 fnto(
  / Yu lgchr
   / or oi ee
});
 ()



 This immediately executes your logic as anonymous scope.
PRIVATE PATTERN
vrgton =fnto( {
 a  eCut    ucin)
  vrcut=0
   a on    ;
  rtr fnto( {
   eun ucin)
     rtr +cut
      eun +on;
  }
}
vrnx =gton(;
 a  et   eCut)
cnoelgnx() / 1
 osl.o(et); /
cnoelgnx() / 2
 osl.o(et); /



This pattern allows you to expose only what you want exposed.
INITIALIZATION
                   Variable initialization:
vrvle=vle| 'oeau'
 a au  au | smvle;



                Complex object initialization:
({
  vl:1
   a1  ,
  vl:nl,
   a2  ul
  ii:fnto( {
   nt  ucin)
    ti.a2=2
     hsvl   ;
    rtr ti;
     eun hs
  }
}.nt)
 )ii(;
LET'S GO OVER JQUERY OPTIMIZATION.
SELECTOR CACHING
                    Bad:
$'smcas)tx(rpaesm tx.)
 (.oels'.et'elc oe et';
$'smcas)cs'oo' 'e';
 (.oels'.s(clr, rd)
$'smcas)fcs)
 (.oels'.ou(;



                    Good:
$'smcas)
 (.oels'
  .et'elc sm tx.)
   tx(rpae oe et'
  .s(clr,'e'
   cs'oo' rd)
  .ou(;
   fcs)
SELECTOR CACHING
             Caching with callbacks.
vr$oetecas=$'smohrls';
 a  smohrls  (.oetecas)
$'smcas)o(cik,fnto(){
 (.oels'.n'lc' ucine
  $oetecastx(sm eet)
   smohrls.et'oe vn';
};
 )



                 Caching "this":
$'smcas)o(cik,fnto() {
 (.oels'.n'lc' ucine)
  $hs=$ti)
   ti  (hs;
  $hstx(smtig)
   ti.et'oehn';
  $hshd(;
   ti.ie)
};
 )
EVENT ATTACHING
     When attaching events, use the "on" function.
$''.n'lc' fnto() {
 (a)o(cik, ucine)
  cnoelg' ln wscikd';
   osl.o(A ik a lce.)
};
 )



       What about dynamically generated links?
$dcmn)o(cik,'' fnto() {
 (ouet.n'lc' a, ucine)
  cnoelg' ln wscikd';
   osl.o(A ik a lce.)
};
 )
PROPERLY STOPPING EVENTS
       Returning false is not always a good thing:
$''.n'lc' fnto(){
 (a)o(cik, ucine
  cnoelg'tpigpoaain';
   osl.o(Sopn rpgto.)
  rtr fle
   eun as;
  / Sm a:
   / ae s
  / epeeteal(;
   / .rvnDfut)
  / esoPoaain)
   / .tprpgto(;
};
 )
$''.n'lc' fnto() {
 (a)o(cik, ucine)
  cnoelg'nte cik';
   osl.o(Aohr lc.)
  / Nvrgt cle bcueo te
   / ee  es ald eas f h
  / rtr flei teaoeeet
   / eun as n h bv vn.
};
 )
BASIC JQUERY PLUGIN STRUCTURE
(ucin$ {
 fnto()
  $f.yo =fnto( {
   .nmLg  ucin)
     rtr ti.ahfnto( {
      eun hsec(ucin)
          cnoelg$ti);
           osl.o((hs)
     };
      )
  }
}jur);
 (Qey)



                   Usage:
$''.yo(;
 (p)mLg)
INTRODUCTION TO NODEJS
Nodejs is an event-driven language built on Google's V8 (in c).

It's package manager is known as npm and is now packaged with
                            nodejs.
NODEJS: HELLO WORLD
vrht =rqie'tp)
 a  tp  eur(ht';
ht.raeevrfnto (e,rs {
 tpcetSre(ucin rq e)
  rswieed20 {CnetTp' 'etpan};
   e.rtHa(0, 'otn-ye: tx/li')
  rsed'el Wrdn)
   e.n(Hlo ol';
}.itn13)
 )lse(37;
cnoelg'evrrnigo pr 13';
 osl.o(Sre unn n ot 37)


             Source:   http://nodejs.org/about/
NODEJS: DEPENDANCY MANAGEMENT
You can manage dependencies for your nodejs app in package.json:
  {
      "ae:"apeap,
       nm"  sml-p"
      "eso" ".."
       vrin: 001,
      "eednis:{
       dpnece"
        "xrs" ".."
         epes: 25x
      }
  }




      This allows us to install our project dependencies with npm:
  nmisal
   p ntl
NODEJS: EXPRESS SERVER
         Our hello world example in express:
vrepes=rqie'xrs';
 a  xrs  eur(epes)
ap=epescetSre(
 p   xrs.raeevr)
apgt'' fnto(e,rs {
 p.e(/, ucinrq e)
  rssn(HloWrd)
   e.ed'el ol';
};
 )
aplse(37;
 p.itn13)
cnoelg'itnn o pr 13';
 osl.o(Lseig n ot 37)
NODEJS: CONNECT MIDDLEWARE
Routing middleware is anything that implements the request,
           response, and next function pattern.
/ Rqetlge
 / eus  ogr
fnto lge(e,rs nx){
 ucin ogrrq e, et
  cnoelg"ahrqetd "+rqpt)
   osl.o(Pt euse:   e.ah;
  nx(;
   et)
}




                  Using this middleware:
apgt'' lge,fnto(e,rs {
 p.e(/, ogr ucinrq e)
  rssn(HloWrd)
   e.ed'el ol';
};
 )
QUESTIONS?
Javascript: The Important Bits

Weitere ähnliche Inhalte

Was ist angesagt?

Os Practical Assignment 1
Os Practical Assignment 1Os Practical Assignment 1
Os Practical Assignment 1
Emmanuel Garcia
 
Reverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operatorReverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operator
erithion
 
Ugly code
Ugly codeUgly code
Ugly code
Odd-e
 
Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2
drewz lin
 

Was ist angesagt? (19)

Os Practical Assignment 1
Os Practical Assignment 1Os Practical Assignment 1
Os Practical Assignment 1
 
Reverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operatorReverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operator
 
What is recursion?
What is recursion? What is recursion?
What is recursion?
 
Presenting Seq for Node.js
Presenting Seq for Node.jsPresenting Seq for Node.js
Presenting Seq for Node.js
 
Ugly code
Ugly codeUgly code
Ugly code
 
C99[2]
C99[2]C99[2]
C99[2]
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihun
 
Build a custom (micro)framework with ZF2 Components (as building blocks)
Build a custom (micro)framework with ZF2 Components (as building blocks)Build a custom (micro)framework with ZF2 Components (as building blocks)
Build a custom (micro)framework with ZF2 Components (as building blocks)
 
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
 
Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
DPC15 uncon talk: How cyborg puppies can sniff out code smell
DPC15 uncon talk: How cyborg puppies can sniff out code smellDPC15 uncon talk: How cyborg puppies can sniff out code smell
DPC15 uncon talk: How cyborg puppies can sniff out code smell
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
 
The Ring programming language version 1.3 book - Part 17 of 88
The Ring programming language version 1.3 book - Part 17 of 88The Ring programming language version 1.3 book - Part 17 of 88
The Ring programming language version 1.3 book - Part 17 of 88
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
 
Usp
UspUsp
Usp
 
gemdiff
gemdiffgemdiff
gemdiff
 

Andere mochten auch (9)

Facebook Social Media
Facebook Social MediaFacebook Social Media
Facebook Social Media
 
Dutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: DistilledDutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: Distilled
 
E business brix
E business brixE business brix
E business brix
 
10576
1057610576
10576
 
New things in php
New things in phpNew things in php
New things in php
 
From Corporate Research 2 start-ups: chronicles of an ongoing journey
From Corporate Research 2 start-ups: chronicles of an ongoing journeyFrom Corporate Research 2 start-ups: chronicles of an ongoing journey
From Corporate Research 2 start-ups: chronicles of an ongoing journey
 
Teatro solange
Teatro solangeTeatro solange
Teatro solange
 
Регистрация товарного знака в России
Регистрация товарного знака в РоссииРегистрация товарного знака в России
Регистрация товарного знака в России
 
Improvevlogteamfame
ImprovevlogteamfameImprovevlogteamfame
Improvevlogteamfame
 

Ähnlich wie Javascript: The Important Bits

Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
Chris Saylor
 
Creating windows store java script apps
Creating windows store java script appsCreating windows store java script apps
Creating windows store java script apps
Eugene Zharkov
 
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from PerlHacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
typester
 
Nginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with LuaNginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with Lua
Tony Fabeen
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
Tony Fabeen
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
priestmanmable
 

Ähnlich wie Javascript: The Important Bits (20)

JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Creating windows store java script apps
Creating windows store java script appsCreating windows store java script apps
Creating windows store java script apps
 
A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1
 
Asynchronous java script
Asynchronous java scriptAsynchronous java script
Asynchronous java script
 
Automated tests - facts and myths
Automated tests - facts and mythsAutomated tests - facts and myths
Automated tests - facts and myths
 
Javascript fundamentals for php developers
Javascript fundamentals for php developersJavascript fundamentals for php developers
Javascript fundamentals for php developers
 
Promises in JavaScript
Promises in JavaScriptPromises in JavaScript
Promises in JavaScript
 
JavaScript pitfalls
JavaScript pitfallsJavaScript pitfalls
JavaScript pitfalls
 
Advanced QUnit - Front-End JavaScript Unit Testing
Advanced QUnit - Front-End JavaScript Unit TestingAdvanced QUnit - Front-End JavaScript Unit Testing
Advanced QUnit - Front-End JavaScript Unit Testing
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from PerlHacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
 
Nginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with LuaNginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with Lua
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
ES6, 잘 쓰고 계시죠?
ES6, 잘 쓰고 계시죠?ES6, 잘 쓰고 계시죠?
ES6, 잘 쓰고 계시죠?
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
One page app with AngularJS
One page app with AngularJSOne page app with AngularJS
One page app with AngularJS
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
+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@
 

Kürzlich hochgeladen (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
+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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Javascript: The Important Bits

  • 1. JAVASCRIPT: THE IMPORTANT BITS REVIEWING JAVASCRIPT AND JQUERY FUNDAMENTALS AS WELL AS A BRIEF INTRO TO NODEJS Chris Saylor ( @cjsaylor ) from Zumba Fitness ®
  • 2. THINK YOU KNOW JAVASCRIPT? typeof [] === "array"; false 0.1 + 0.2 === 0.3; false a === null; false 0 == '0'; true 1 == '1'; true '' == '0'; false '' == 0; true 'false' == false; false True or false?
  • 3. THINK YOU KNOW JAVASCRIPT? rtr eun { a "el" : hlo } What does this return?
  • 4. THINK YOU KNOW JAVASCRIPT?
  • 5. LET'S GET STARTED WITH THE BASICS.
  • 6. VARIABLES When declairing a variable without the "var", it puts the variable in global space which can be problematic. fnto hlo){ ucin el( ts1='el' et hlo; / goa soe / lbl cp vrts2='el2; / ti fnto soe a et hlo' / hs ucin cp } hlo) el(; cnoelgts1;/ 'el' osl.o(et) / hlo; cnoelgts2;/ udfnd osl.o(et) / neie
  • 7. SCOPING There is no block scoping, only function scoping: fr(a i=0 i<1;i+ { o vr ; 0 +) cnoelgi; osl.o() } cnoelgi;/ pit 1 osl.o() / rns 0 If you want to block the scope of the above loop: (ucin( { fnto ) fr(a i=0 i<1;i+ { o vr ; 0 +) cnoelgi; osl.o() } }); () vri a ; cnoelgi;/ udfnd osl.o() / neie
  • 8. SCOPE IN CALLBACKS In callbacks, you can share variables from the parent function: vroj={ a b ojau:'el' bVle hlo, ts:fnto( { et ucin) vrsl =ti; a ef hs stieu(ucin){ eTmotfnto( cnoelgti.bVle;/ udfnd osl.o(hsojau) / neie cnoelgsl.bVle;/ 'el' osl.o(efojau) / hlo } 1) , 0; } }
  • 9. OBJECTS AND "CLASSES" Objects are like JSON with some class aspects known as prototypes.
  • 10. OBJECTS AND "CLASSES" An example class: Aia =(ucin){ nml fnto( fnto Aia(ae { ucin nmlnm) ti.ae=nm; hsnm ae } Aia.rttp.oe=fnto( { nmlpooyemv ucin) rtr aetti.ae+'mvd'; eun lr(hsnm oe.) }; rtr Aia; eun nml }); ()
  • 12. IMMEDIATE EXECUTION FUNCTION (ucin){ fnto( / Yu lgchr / or oi ee }); () This immediately executes your logic as anonymous scope.
  • 13. PRIVATE PATTERN vrgton =fnto( { a eCut ucin) vrcut=0 a on ; rtr fnto( { eun ucin) rtr +cut eun +on; } } vrnx =gton(; a et eCut) cnoelgnx() / 1 osl.o(et); / cnoelgnx() / 2 osl.o(et); / This pattern allows you to expose only what you want exposed.
  • 14. INITIALIZATION Variable initialization: vrvle=vle| 'oeau' a au au | smvle; Complex object initialization: ({ vl:1 a1 , vl:nl, a2 ul ii:fnto( { nt ucin) ti.a2=2 hsvl ; rtr ti; eun hs } }.nt) )ii(;
  • 15. LET'S GO OVER JQUERY OPTIMIZATION.
  • 16. SELECTOR CACHING Bad: $'smcas)tx(rpaesm tx.) (.oels'.et'elc oe et'; $'smcas)cs'oo' 'e'; (.oels'.s(clr, rd) $'smcas)fcs) (.oels'.ou(; Good: $'smcas) (.oels' .et'elc sm tx.) tx(rpae oe et' .s(clr,'e' cs'oo' rd) .ou(; fcs)
  • 17. SELECTOR CACHING Caching with callbacks. vr$oetecas=$'smohrls'; a smohrls (.oetecas) $'smcas)o(cik,fnto(){ (.oels'.n'lc' ucine $oetecastx(sm eet) smohrls.et'oe vn'; }; ) Caching "this": $'smcas)o(cik,fnto() { (.oels'.n'lc' ucine) $hs=$ti) ti (hs; $hstx(smtig) ti.et'oehn'; $hshd(; ti.ie) }; )
  • 18. EVENT ATTACHING When attaching events, use the "on" function. $''.n'lc' fnto() { (a)o(cik, ucine) cnoelg' ln wscikd'; osl.o(A ik a lce.) }; ) What about dynamically generated links? $dcmn)o(cik,'' fnto() { (ouet.n'lc' a, ucine) cnoelg' ln wscikd'; osl.o(A ik a lce.) }; )
  • 19. PROPERLY STOPPING EVENTS Returning false is not always a good thing: $''.n'lc' fnto(){ (a)o(cik, ucine cnoelg'tpigpoaain'; osl.o(Sopn rpgto.) rtr fle eun as; / Sm a: / ae s / epeeteal(; / .rvnDfut) / esoPoaain) / .tprpgto(; }; ) $''.n'lc' fnto() { (a)o(cik, ucine) cnoelg'nte cik'; osl.o(Aohr lc.) / Nvrgt cle bcueo te / ee es ald eas f h / rtr flei teaoeeet / eun as n h bv vn. }; )
  • 20. BASIC JQUERY PLUGIN STRUCTURE (ucin$ { fnto() $f.yo =fnto( { .nmLg ucin) rtr ti.ahfnto( { eun hsec(ucin) cnoelg$ti); osl.o((hs) }; ) } }jur); (Qey) Usage: $''.yo(; (p)mLg)
  • 22. Nodejs is an event-driven language built on Google's V8 (in c). It's package manager is known as npm and is now packaged with nodejs.
  • 23. NODEJS: HELLO WORLD vrht =rqie'tp) a tp eur(ht'; ht.raeevrfnto (e,rs { tpcetSre(ucin rq e) rswieed20 {CnetTp' 'etpan}; e.rtHa(0, 'otn-ye: tx/li') rsed'el Wrdn) e.n(Hlo ol'; }.itn13) )lse(37; cnoelg'evrrnigo pr 13'; osl.o(Sre unn n ot 37) Source: http://nodejs.org/about/
  • 24. NODEJS: DEPENDANCY MANAGEMENT You can manage dependencies for your nodejs app in package.json: { "ae:"apeap, nm" sml-p" "eso" ".." vrin: 001, "eednis:{ dpnece" "xrs" ".." epes: 25x } } This allows us to install our project dependencies with npm: nmisal p ntl
  • 25. NODEJS: EXPRESS SERVER Our hello world example in express: vrepes=rqie'xrs'; a xrs eur(epes) ap=epescetSre( p xrs.raeevr) apgt'' fnto(e,rs { p.e(/, ucinrq e) rssn(HloWrd) e.ed'el ol'; }; ) aplse(37; p.itn13) cnoelg'itnn o pr 13'; osl.o(Lseig n ot 37)
  • 26. NODEJS: CONNECT MIDDLEWARE Routing middleware is anything that implements the request, response, and next function pattern. / Rqetlge / eus ogr fnto lge(e,rs nx){ ucin ogrrq e, et cnoelg"ahrqetd "+rqpt) osl.o(Pt euse: e.ah; nx(; et) } Using this middleware: apgt'' lge,fnto(e,rs { p.e(/, ogr ucinrq e) rssn(HloWrd) e.ed'el ol'; }; )