SlideShare a Scribd company logo
1 of 28
Download to read offline
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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked (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
 

Similar to 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
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
priestmanmable
 

Similar to 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
 
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
 
Expression trees in c#
Expression trees in c#Expression trees in c#
Expression trees in c#
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at Google
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 

Recently uploaded (20)

Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 

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'; }; )