SlideShare a Scribd company logo
1 of 47
Download to read offline
JS Best Practices
Created by Johannes Hoppe
My Goal
Higher code qualitiy. Pragmatic solutions.
             No fancy stuff.
Know Your
 MS Tools
Visual Studio 2010/2012
JScript Editor Extensions
Resharper 7.1
JSHint
Chutzpah
Firebug / F12
Know the
 pitfalls
Implied globals
               Forgetting var

vrfo=fnto( {
 a o   ucin)
   br=1
   a   ;
};
Boolean type conversion
         To Truthy or to Falsy. That is the only question!

vre =dcmn.eEeetyd'osnteit)
a l   ouetgtlmnBI(de_o_xs';

i(l= fle {
 fe = as)
   aet"hud' w seti msae!)
   lr(solnt e e hs esg?";
}
Trailing comma
            works on my machine!

vrfo={
 a o
   br "a"
   a: br,
   bz "a"
   a: bz,
};
Return undefined
             señor developers wear mustaches




                       {
vrfo=fnto( {
 a o    ucin)
   rtr
    eun
   {
      x:"ok lk C nw"
         los ie # o!
   };
}
Associative arrays
             they don't exist

vrx=[;
a    ]
x'o' ="a"
[fo]   br;
try .. catch .. finally
                 who cares about the reason?

vrfo=fnto( {
 a o     ucin)
   ty{
    r
      dCaytf;
       orzSuf
   }cth(){
      ac e
       rtr fle
       eun as;
   }
   rtr tu;
    eun re
};
for .. in
                 use a framework

vrdt ={
 a aa
   fo "h,
   o: o"
   br "y
   a: m"
}

fr(a di dt){
 o vr  n aa
   cnoelgdt[];
   osl.o(aad)
}
for .. in
           & never touch Object.prototype

 Ojc.rttp.eAohrotig=fnto( {
  betpooyeytnteTSrn  ucin)
   rtr "o"
   eun gd;
}
Hoisting
                declare upfront all variables

vrfo="lbl;
 a o goa"

vrbr=fnto( {
 a a   ucin)
   aetfo;
   lr(o)
   vrfo="oa"
   a o   lcl;
   aetfo;
   lr(o)
};
Eval
               ... and the job is done

fnto poMnJoPre(et {
 ucin orassnasrtx)
   rtr ea(( +tx +"";
   eun vl""  et   ))
}

vrtx ='{"el":"ol"}'
a et     hlo  wrd  ;
vrjo =poMnJoPre(et;
a sn  orassnasrtx)
Eval is evil!
                Never ever!

vrtx ='fnto( {aet"akd";}('
a et   ucin)   lr(hce!) ) ;
Globals
             the mother of all antipatterns

fnto fo){
 ucin o(
   rtr "a"
   eun br;
}

cnoelgti[fo]);
osl.o(hs'o'()
Every time you clutter the global namespace,
somewhere in the world a helpless kitten dies!
Pretty Code
Coding conventions
 1.   intentation (4 spaces!)
 2.   curly braces everywhere
 3.   semicolons everywhere
 4.   constructor functions: UpperCamelCase
 5.   all other: lowerCamelCase
Globals
          reduce, minimize, delete or kill them

(ucin){"t? }(;
fnto(   wf" ))
The switch-case
         syndrome
               a functional language wants functions!

sic (oehn){
wth smtig

    cs 1
    ae :
      dFrt)
       ois(;
      bek
       ra;

    cs 2
    ae :
      dScn(;
       oeod)
      bek
       ra;

    cs 3
    ae :
      dTid)
       ohr(;
      bek
       ra;
}
Lookup tables
            avoid the switch-case syndrome

vrmtos={
 a ehd
   1 dFrt
    : ois,
   2 dScn,
    : oeod
   3 dTid
    : ohr
};
i (ehd[oehn] {
 f mtossmtig)
   mtossmtig(;
    ehd[oehn])
}
Inheritance
       favour composition over inheritance (FCoI)



“ Because inheritance exposes a subclass
to details of its parent's implementation,
  it's often said that 'inheritance breaks
              encapsulation'. ”
                                                    (Gang of Four 1995:19)
Revealing Module
            Pattern
vrmRvaigoue=fnto ( {
a yeelnMdl   ucin )

    vr_ae="oans;
    a nm  Jhne"

    fnto getns){
     ucin reig(
       cnoelg"el "+_ae;
       osl.o(Hlo    nm)
    }

    fnto staenm){
     ucin eNm(ae
       _ae=nm;
       nm  ae
    }

   rtr {
    eun
      stae stae
      eNm: eNm,
      getns getns
      reig: reig
   };
})
(;

» Documentation
Modul loaders
                 use AMD (require.js)

dfn(ts' [jur',fnto( {
eie'et, 'qey] ucin)

     rtr {
      eun
        syoehn :fnto( {aet"el!) }
        aSmtig   ucin)  lr(hlo";
     }
};
)

rqie[ts',fnto(){
eur('et] ucint
   tsyoehn(;
   .aSmtig)
};
)
Events
              Publish/Subscribe Pattern

vr$vns=${)
a eet   (};

$vnsbn(smtigapn' fnto( {
eet.id'oehnHpes, ucin)
   aet"oehn hpee!)
   lr(Smtig apnd";
};
)

$vnstigr'oehnHpes)
eet.rge(smtigapn';
TDD with Jasmine
Why Jasmine?
              similar to JSpec or RSpec,
 BDD-style    created by authors of jsUnit and Screw.Unit

              from any browser, DOM,
independent   framework or host language

              into continuous build systems
integrates
Jasmine Bootstrap
<DCYEhm>
!OTP tl
<tl
hm>
<ed
ha>
  <il>amn Se Rne<tte
   tteJsie pc unr/il>

  <ikrl"tlset he=lbjsie131jsiecs /
   ln e=syehe" rf"i/amn-../amn.s" >
  <citsc"i/amn-../amn.s>/cit
   srp r=lbjsie131jsiej"<srp>
  <citsc"i/amn-../amn-tlj"<srp>
   srp r=lbjsie131jsiehm.s>/cit

  <- icuesuc flshr..->
   !- nld ore ie ee. -
  <citsc"r/lyrj"<srp>
   srp r=scPae.s>/cit
  <citsc"r/ogj"<srp>
   srp r=scSn.s>/cit

  <- icuese flshr..->
   !- nld pc ie ee. -
  <citsc"pcSeHle.s>/cit
   srp r=se/pceprj"<srp>
  <citsc"pcPaeSe.s>/cit
   srp r=se/lyrpcj"<srp>

  <cit
   srp>

    (ucin( {
     fnto )

      vrhmRpre =nwjsieHmRpre(;
       a tleotr  e amn.tleotr)
      vrjsien =jsiegtn(;
       a amnEv  amn.eEv)

      jsien.dRpre(tleotr;
       amnEvadeotrhmRpre)
      jsien.pcitr=fnto (pc {
       amnEvseFle    ucin se)
         rtr hmRpre.pcitrse)
          eun tleotrseFle(pc;
      };

      vrcretidwnod=wno.nod
       a urnWnoOla  idwola;

      wno.nod=fnto ( {
       idwola ucin )
Output
Jsie131rvso 15561
 amn .. eiin 34593                     fnse i 008
                                        iihd n .1s

•••••

Psig5ses
 asn  pc                                 N tycth
                                          o r/ac

Pae
 lyr
  sol b al t pa aSn
   hud e be o ly  og

 we sn hsbe pue
  hn og a  en asd
   sol idct ta tesn i cretypue
    hud niae ht h  og s urnl  asd
   sol b psil t rsm
    hud e osbe o eue
 tlstecretsn i teue hsmd i afvrt
  el  h  urn og f h  sr a ae t  aoie

 #eue
  rsm
   sol trwa ecpini sn i araypaig
    hud ho n xeto f og s led lyn
Hello World
vrhlool =fnto( {
 a elWrd   ucin)
   rtr "el Wrd"
   eun Hlo ol!;
};

dsrb(hlool' fnto( {
ecie'elWrd, ucin)
  i(sy hlo,fnto( {
  t'as el' ucin)

          epc(elWrd).oqa(HloWrd";
          xethlool()tEul"el ol!)
     };
     )
};
)

jsiegtn(.xct(;
amn.eEv)eeue)

                             hint: press F12 and paste this code!
Matchers
epc()tEuly;
xetx.oqa()
epc()tB()
xetx.oey;
epc()tMthpten;
xetx.oac(atr)
epc()tBDfnd)
xetx.oeeie(;
epc()tBUdfnd)
xetx.oeneie(;
epc()tBNl(;
xetx.oeul)
epc()tBTuh(;
xetx.oerty)
epc()tBFly)
xetx.oeas(;
epc()tCnany;
xetx.ooti()
epc()tBLsTa()
xetx.oeeshny;
epc()tBGetrhny;
xetx.oeraeTa()
epc(ucin)f(;)tTrwe;
xetfnto({n)}.oho()
Own matchers
bfrEc(ucin( {
eoeahfnto )
   ti.dMthr(
   hsadaces{
      iAa:fnto ( {
       sCt ucin )
        rtr ti.culiFuf( & ti.culiLz(;
         eun hsata.slfy) & hsata.say)
      }
   };
   )
};
)

dsrb(Gril' fnto ( {
ecie'afed, ucin )
   i(i act,fnto ( {
   t's   a' ucin )
      epc(e Gril()iAa(;
      xetnw afed).sCt)
   };
   )
};
)

» Documentation
Test-Driven Development
                                     1.   Write your tests
                                     2.   Watch them fail
                                     3.   Make them pass
                                     4.   Refactor
                                     5.   Repeat


 see   Growing Object-Oriented Software, Guidedorby Tests , page 6
 see   Working Effectively with Legacy Code , page 62 many other
1. Write your test
dsrb(svFra" fnto ( {
ecie"aeomt, ucin )

     vroiia ='0 -{}-{};
     a rgnl   {}  1 2'

     i(sol rpaepaeodr" fnto ( {
     t"hud elc lchles, ucin )
        vrepce =' -B-C;
        a xetd   A   '
        vrfrae =svFra(rgnl '' '' '';
        a omtd   aeomtoiia, A, B, C)
        epc(omtd.oqa(xetd;
        xetfrae)tEulepce)
     };
     )

     i(sol ecd ijce cnet,fnto ( {
     t"hud noe netd otn" ucin )
        vrepce =' -&tbg;ETl;bg;-C;
        a xetd   A  l;&tTS&t/&t   '
        vrfrae =svFra(rgnl '' 'bTS<b' '';
        a omtd   aeomtoiia, A, <>ET/>, C)
        epc(omtd.oqa(xetd;
        xetfrae)tEulepce)
     };
     )
};
)
2. Watch them fail
vrsvFra =fnto( {
 a aeomt   ucin)
   rtr "o!;
   eun bo"
};
jsiegtn(.xct(;
 amn.eEv)eeue)

Demo
3. Make them pass
vrsvFra =fnto(x){
a aeomt   ucintt

   $agmns.ahfnto (,ie){
   (ruet)ec(ucin i tm
      i ( >0 {
       f i   )
         ie =((<i/'.etie)hm()
          tm    $'dv>)tx(tm.tl);
         tt=ttrpae""+( -1 +"" ie)
          x    x.elc({   i )  }, tm;
      }
   };
   )
   rtr tt
   eun x;
};
jsiegtn(.xct(;
 amn.eEv)eeue)

Demo
4. Refactor
fnto hmEcd(nu){
 ucin tlnoeipt
   rtr ((<i/'.etipt.tl);
   eun $'dv>)tx(nu)hm()
}

vrsvFra =fnto(x){
a aeomt   ucintt

   $ec(ruet,fnto (,ie){
   .ahagmns ucin i tm
      i ( >0 {
       f i   )
         ie =hmEcd(tm;
          tm    tlnoeie)
         tt=ttrpae""+( -1 +"" ie)
          x    x.elc({   i ) }, tm;
      }
   };
   )
   rtr tt
   eun x;
};
jsiegtn(.xct(;
 amn.eEv)eeue)

Demo
5. Repeat
fnto hmEcd(nu){
 ucin tlnoeipt
   rtr ((<i/'.etipt.tl);
   eun $'dv>)tx(nu)hm()
}

vrsvFra =fnto( {
a aeomt   ucin)

   vrag =Arypooyesiecl(ruet)
   a rs   ra.rttp.lc.alagmns;
   vrtt=ag.hf(;
   a x   rssit)

   $ec(rs fnto (,ie){
   .ahag, ucin i tm
      ie =hmEcd(tm;
      tm   tlnoeie)
      tt=ttrpae""+i+"" ie)
      x   x.elc({    }, tm;
   };
   )
   rtr tt
   eun x;
};
jsiegtn(.xct(;
 amn.eEv)eeue)

Demo
Testing HTML
        Jasmine is DOM agnostic
comes without tools to set up HTML fixtures


                                                             Definition:
                              A test fixture is a fixed state of a set of
                           objects used as a baseline for running tests.
First Solution
            in memory fixture with jQuery

dsrb(tiiljur pui' fnto ( {
ecie'rva Qey lgn, ucin )

  vrfxue
  a itr;
  bfrEc(ucin( {
  eoeahfnto )
     fxue=$'dvsm HM cd hr<dv';
     itr  (<i>oe TL oe ee/i>)
  };
  )

  i(sol d smtig,fnto ( {
  t'hud o oehn' ucin )
     fxuemPui(;
     itr.ylgn)
     epc(itr)tHvCas"eCas)
     xetfxue.oaels(nwls";
  };
  )
};
)
jsiegtn(.xct(;
amn.eEv)eeue)

            ... only works for trivial plugins!
Clumsy Solution
           directly append to/remove from DOM

dsrb(m jur pui' fnto ( {
ecie'y Qey lgn, ucin )

  bfrEc(ucin( {
  eoeahfnto )
     $'fxue)rmv(;
     (#itr'.eoe)
     $'oy)apn(<i i=fxue>TL/i>)
     (bd'.ped'dv d"itr"HM<dv';
  };
  )

  i(sol d smtig,fnto ( {
  t'hud o oehn' ucin )
     $'fxue)mPui(;
     (#itr'.ylgn)
     epc((#itr')tHvCas"eCas)
     xet$'fxue).oaels(nwls";
  };
  )
};
)
jsiegtn(.xct(;
amn.eEv)eeue)
jasmine-jquery
         custom matchers , HTML/style/JSON fixtures, event spies

dsrb(m jur pui' fnto ( {
ecie'y Qey lgn, ucin )

  bfrEc(ucin){
   eoeahfnto(
     jsiegtitrs)fxuePt=j/_amn-eojur'
      amn.eFxue(.itrsah's5jsiedm_qey;
     jsiegtitrs)la(jur.ylgnse.tl)
      amn.eFxue(.od'qeymPui.pchm';
  };
   )

  i(sol d smtig,fnto( {
   t'hud o oehn' ucin)

       vr$i =$'hlool'.ylgn)
        a dv (#elWrd)mPui(;
       epc(dv.oaels(nwls";
        xet$i)tHvCas"eCas)
  };
   )
};
)
jsiegtn(.xct(;
amn.eEv)eeue)

Demo
TDD → BDD
Spies
                           test behaviour

dsrb(Gril' fnto ( {
ecie'afed, ucin )
  dsrb(we tl t b nc' fnto( {
   ecie'hn od o e ie, ucin)

       vrgril;
        a afed
       bfrEc(ucin){
        eoeahfnto(
          gril =nwGril(;
           afed  e afed)
          syngril,'oordenEtiz'.nClTruh)
           pO(afed gTFigAdaPza)adalhog(;
       };
        )

       i(sol ase wt o' fnto( {
        t'hud nwr ih k, ucin)
          vrase =gril.eie)
           a nwr  afedbNc(;
          epc(nwr.oqa(o";
           xetase)tEul"k)
       };
        )

       i(sol selpza,fnto ( {
        t'hud ta iz' ucin )
          gril.eie)
           afedbNc(;
          epc(afedgTFigAdaPza.oaeenald)
           xetgril.oordenEtiz)tHvBeCle(;
       };
        )
   };
    )
};
)
jsiegtn(.xct(;
amn.eEv)eeue)


                                 A spy can stub any function and tracks calls to it and all arguments.



Demo
Danke!

More Related Content

What's hot

How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...Ari Lerner
 
Proxy OOP Pattern in PHP
Proxy OOP Pattern in PHPProxy OOP Pattern in PHP
Proxy OOP Pattern in PHPMarco Pivetta
 
Javascript fundamentals for php developers
Javascript fundamentals for php developersJavascript fundamentals for php developers
Javascript fundamentals for php developersChris Ramakers
 
Executable documentation
Executable documentationExecutable documentation
Executable documentationRussell Gold
 
Unit testing with PHPUnit
Unit testing with PHPUnitUnit testing with PHPUnit
Unit testing with PHPUnitferca_sl
 
Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton Arhipov
 
Testing for Unicorns
Testing for UnicornsTesting for Unicorns
Testing for UnicornsAlex Soto
 
Потоки в перле изнутри
Потоки в перле изнутриПотоки в перле изнутри
Потоки в перле изнутриIlya Zelenchuk
 
Start Writing Groovy
Start Writing GroovyStart Writing Groovy
Start Writing GroovyEvgeny Goldin
 
start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()Kiwamu Okabe
 
A Prettier Printer
A Prettier PrinterA Prettier Printer
A Prettier Printerjlongster2
 
Awesomely descriptive JavaScript with monads
Awesomely descriptive JavaScript with monadsAwesomely descriptive JavaScript with monads
Awesomely descriptive JavaScript with monadsMichal Nowak
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS TestingEyal Vardi
 
Os Practical Assignment 1
Os Practical Assignment 1Os Practical Assignment 1
Os Practical Assignment 1Emmanuel Garcia
 
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 88Mahmoud Samir Fayed
 

What's hot (20)

How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
 
Proxy OOP Pattern in PHP
Proxy OOP Pattern in PHPProxy OOP Pattern in PHP
Proxy OOP Pattern in PHP
 
Javascript fundamentals for php developers
Javascript fundamentals for php developersJavascript fundamentals for php developers
Javascript fundamentals for php developers
 
Executable documentation
Executable documentationExecutable documentation
Executable documentation
 
Unit testing with PHPUnit
Unit testing with PHPUnitUnit testing with PHPUnit
Unit testing with PHPUnit
 
Lisp
LispLisp
Lisp
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
Testing for Unicorns
Testing for UnicornsTesting for Unicorns
Testing for Unicorns
 
Потоки в перле изнутри
Потоки в перле изнутриПотоки в перле изнутри
Потоки в перле изнутри
 
Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9
 
What is recursion?
What is recursion? What is recursion?
What is recursion?
 
Start Writing Groovy
Start Writing GroovyStart Writing Groovy
Start Writing Groovy
 
start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()
 
A Prettier Printer
A Prettier PrinterA Prettier Printer
A Prettier Printer
 
Awesomely descriptive JavaScript with monads
Awesomely descriptive JavaScript with monadsAwesomely descriptive JavaScript with monads
Awesomely descriptive JavaScript with monads
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS Testing
 
Sbaw091006
Sbaw091006Sbaw091006
Sbaw091006
 
Os Practical Assignment 1
Os Practical Assignment 1Os Practical Assignment 1
Os Practical Assignment 1
 
Usp
UspUsp
Usp
 
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
 

Viewers also liked

Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practicesManav Gupta
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptWebF
 

Viewers also liked (6)

Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Predictive Modelling
Predictive ModellingPredictive Modelling
Predictive Modelling
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 

Similar to 2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices

Creating windows store java script apps
Creating windows store java script appsCreating windows store java script apps
Creating windows store java script appsEugene Zharkov
 
Presenting Seq for Node.js
Presenting Seq for Node.jsPresenting Seq for Node.js
Presenting Seq for Node.jsDouglas Muth
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design PatternsDerek Brown
 
SecureSocial - Authentication for Play Framework
SecureSocial - Authentication for Play FrameworkSecureSocial - Authentication for Play Framework
SecureSocial - Authentication for Play Frameworkjaliss
 
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 1jsalonen Salonen
 
Building modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and javaBuilding modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and javaAlexander Gyoshev
 
nescala 2013
nescala 2013nescala 2013
nescala 2013Hung Lin
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015Phillip Trelford
 
Automated tests - facts and myths
Automated tests - facts and mythsAutomated tests - facts and myths
Automated tests - facts and mythsWojciech Sznapka
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best PracticesEdorian
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony componentsMichael Peacock
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
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)Pavlo Baron
 
Learn Frontend Testing
Learn Frontend TestingLearn Frontend Testing
Learn Frontend TestingRyan Roemer
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunJIHUN KIM
 
Clojurescript up and running
Clojurescript up and runningClojurescript up and running
Clojurescript up and runningTimo Sulg
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talkJohn Stevenson
 
Theme Development and Customization
Theme Development and CustomizationTheme Development and Customization
Theme Development and CustomizationAniket Pant
 

Similar to 2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices (20)

Creating windows store java script apps
Creating windows store java script appsCreating windows store java script apps
Creating windows store java script apps
 
Presenting Seq for Node.js
Presenting Seq for Node.jsPresenting Seq for Node.js
Presenting Seq for Node.js
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 
SecureSocial - Authentication for Play Framework
SecureSocial - Authentication for Play FrameworkSecureSocial - Authentication for Play Framework
SecureSocial - Authentication for Play Framework
 
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
 
Building modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and javaBuilding modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and java
 
nescala 2013
nescala 2013nescala 2013
nescala 2013
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
Automated tests - facts and myths
Automated tests - facts and mythsAutomated tests - facts and myths
Automated tests - facts and myths
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
Music as data
Music as dataMusic as data
Music as data
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
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)
 
Ff to-fp
Ff to-fpFf to-fp
Ff to-fp
 
Learn Frontend Testing
Learn Frontend TestingLearn Frontend Testing
Learn Frontend Testing
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihun
 
Clojurescript up and running
Clojurescript up and runningClojurescript up and running
Clojurescript up and running
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
Theme Development and Customization
Theme Development and CustomizationTheme Development and Customization
Theme Development and Customization
 

More from Johannes Hoppe

2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung MosbachJohannes Hoppe
 
Einführung in Angular 2
Einführung in Angular 2Einführung in Angular 2
Einführung in Angular 2Johannes Hoppe
 
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und IonicMDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und IonicJohannes Hoppe
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung MosbachJohannes Hoppe
 
2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf AzureJohannes Hoppe
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript SecurityJohannes Hoppe
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScriptJohannes Hoppe
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScriptJohannes Hoppe
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript SecurityJohannes Hoppe
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL SpartakiadeJohannes Hoppe
 
2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo dbJohannes Hoppe
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGLJohannes Hoppe
 
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und MongodbJohannes Hoppe
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGLJohannes Hoppe
 
2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDBJohannes Hoppe
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)Johannes Hoppe
 
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDBJohannes Hoppe
 
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDBJohannes Hoppe
 
2012-04-12 - AOP .NET UserGroup Niederrhein
2012-04-12 - AOP .NET UserGroup Niederrhein2012-04-12 - AOP .NET UserGroup Niederrhein
2012-04-12 - AOP .NET UserGroup NiederrheinJohannes Hoppe
 

More from Johannes Hoppe (20)

2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach
 
NoSQL - Hands on
NoSQL - Hands onNoSQL - Hands on
NoSQL - Hands on
 
Einführung in Angular 2
Einführung in Angular 2Einführung in Angular 2
Einführung in Angular 2
 
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und IonicMDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
 
2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript Security
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade
 
2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
 
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL
 
2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
 
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
 
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
 
2012-04-12 - AOP .NET UserGroup Niederrhein
2012-04-12 - AOP .NET UserGroup Niederrhein2012-04-12 - AOP .NET UserGroup Niederrhein
2012-04-12 - AOP .NET UserGroup Niederrhein
 

Recently uploaded

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Recently uploaded (20)

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices

  • 1. JS Best Practices Created by Johannes Hoppe
  • 2. My Goal Higher code qualitiy. Pragmatic solutions. No fancy stuff.
  • 3. Know Your MS Tools
  • 4. Visual Studio 2010/2012 JScript Editor Extensions Resharper 7.1 JSHint Chutzpah Firebug / F12
  • 6. Implied globals Forgetting var vrfo=fnto( { a o ucin) br=1 a ; };
  • 7. Boolean type conversion To Truthy or to Falsy. That is the only question! vre =dcmn.eEeetyd'osnteit) a l ouetgtlmnBI(de_o_xs'; i(l= fle { fe = as) aet"hud' w seti msae!) lr(solnt e e hs esg?"; }
  • 8. Trailing comma works on my machine! vrfo={ a o br "a" a: br, bz "a" a: bz, };
  • 9. Return undefined señor developers wear mustaches { vrfo=fnto( { a o ucin) rtr eun { x:"ok lk C nw" los ie # o! }; }
  • 10. Associative arrays they don't exist vrx=[; a ] x'o' ="a" [fo] br;
  • 11. try .. catch .. finally who cares about the reason? vrfo=fnto( { a o ucin) ty{ r dCaytf; orzSuf }cth(){ ac e rtr fle eun as; } rtr tu; eun re };
  • 12. for .. in use a framework vrdt ={ a aa fo "h, o: o" br "y a: m" } fr(a di dt){ o vr n aa cnoelgdt[]; osl.o(aad) }
  • 13. for .. in & never touch Object.prototype Ojc.rttp.eAohrotig=fnto( { betpooyeytnteTSrn ucin) rtr "o" eun gd; }
  • 14. Hoisting declare upfront all variables vrfo="lbl; a o goa" vrbr=fnto( { a a ucin) aetfo; lr(o) vrfo="oa" a o lcl; aetfo; lr(o) };
  • 15. Eval ... and the job is done fnto poMnJoPre(et { ucin orassnasrtx) rtr ea(( +tx +""; eun vl"" et )) } vrtx ='{"el":"ol"}' a et hlo wrd ; vrjo =poMnJoPre(et; a sn orassnasrtx)
  • 16. Eval is evil! Never ever! vrtx ='fnto( {aet"akd";}(' a et ucin) lr(hce!) ) ;
  • 17. Globals the mother of all antipatterns fnto fo){ ucin o( rtr "a" eun br; } cnoelgti[fo]); osl.o(hs'o'()
  • 18. Every time you clutter the global namespace, somewhere in the world a helpless kitten dies!
  • 20. Coding conventions 1. intentation (4 spaces!) 2. curly braces everywhere 3. semicolons everywhere 4. constructor functions: UpperCamelCase 5. all other: lowerCamelCase
  • 21. Globals reduce, minimize, delete or kill them (ucin){"t? }(; fnto( wf" ))
  • 22. The switch-case syndrome a functional language wants functions! sic (oehn){ wth smtig cs 1 ae : dFrt) ois(; bek ra; cs 2 ae : dScn(; oeod) bek ra; cs 3 ae : dTid) ohr(; bek ra; }
  • 23. Lookup tables avoid the switch-case syndrome vrmtos={ a ehd 1 dFrt : ois, 2 dScn, : oeod 3 dTid : ohr }; i (ehd[oehn] { f mtossmtig) mtossmtig(; ehd[oehn]) }
  • 24. Inheritance favour composition over inheritance (FCoI) “ Because inheritance exposes a subclass to details of its parent's implementation, it's often said that 'inheritance breaks encapsulation'. ” (Gang of Four 1995:19)
  • 25. Revealing Module Pattern vrmRvaigoue=fnto ( { a yeelnMdl ucin ) vr_ae="oans; a nm Jhne" fnto getns){ ucin reig( cnoelg"el "+_ae; osl.o(Hlo nm) } fnto staenm){ ucin eNm(ae _ae=nm; nm ae } rtr { eun stae stae eNm: eNm, getns getns reig: reig }; }) (; » Documentation
  • 26. Modul loaders use AMD (require.js) dfn(ts' [jur',fnto( { eie'et, 'qey] ucin) rtr { eun syoehn :fnto( {aet"el!) } aSmtig ucin) lr(hlo"; } }; ) rqie[ts',fnto(){ eur('et] ucint tsyoehn(; .aSmtig) }; )
  • 27. Events Publish/Subscribe Pattern vr$vns=${) a eet (}; $vnsbn(smtigapn' fnto( { eet.id'oehnHpes, ucin) aet"oehn hpee!) lr(Smtig apnd"; }; ) $vnstigr'oehnHpes) eet.rge(smtigapn';
  • 29. Why Jasmine? similar to JSpec or RSpec, BDD-style created by authors of jsUnit and Screw.Unit from any browser, DOM, independent framework or host language into continuous build systems integrates
  • 30. Jasmine Bootstrap <DCYEhm> !OTP tl <tl hm> <ed ha> <il>amn Se Rne<tte tteJsie pc unr/il> <ikrl"tlset he=lbjsie131jsiecs / ln e=syehe" rf"i/amn-../amn.s" > <citsc"i/amn-../amn.s>/cit srp r=lbjsie131jsiej"<srp> <citsc"i/amn-../amn-tlj"<srp> srp r=lbjsie131jsiehm.s>/cit <- icuesuc flshr..-> !- nld ore ie ee. - <citsc"r/lyrj"<srp> srp r=scPae.s>/cit <citsc"r/ogj"<srp> srp r=scSn.s>/cit <- icuese flshr..-> !- nld pc ie ee. - <citsc"pcSeHle.s>/cit srp r=se/pceprj"<srp> <citsc"pcPaeSe.s>/cit srp r=se/lyrpcj"<srp> <cit srp> (ucin( { fnto ) vrhmRpre =nwjsieHmRpre(; a tleotr e amn.tleotr) vrjsien =jsiegtn(; a amnEv amn.eEv) jsien.dRpre(tleotr; amnEvadeotrhmRpre) jsien.pcitr=fnto (pc { amnEvseFle ucin se) rtr hmRpre.pcitrse) eun tleotrseFle(pc; }; vrcretidwnod=wno.nod a urnWnoOla idwola; wno.nod=fnto ( { idwola ucin )
  • 31. Output Jsie131rvso 15561 amn .. eiin 34593 fnse i 008 iihd n .1s ••••• Psig5ses asn pc N tycth o r/ac Pae lyr sol b al t pa aSn hud e be o ly og we sn hsbe pue hn og a en asd sol idct ta tesn i cretypue hud niae ht h og s urnl asd sol b psil t rsm hud e osbe o eue tlstecretsn i teue hsmd i afvrt el h urn og f h sr a ae t aoie #eue rsm sol trwa ecpini sn i araypaig hud ho n xeto f og s led lyn
  • 32. Hello World vrhlool =fnto( { a elWrd ucin) rtr "el Wrd" eun Hlo ol!; }; dsrb(hlool' fnto( { ecie'elWrd, ucin) i(sy hlo,fnto( { t'as el' ucin) epc(elWrd).oqa(HloWrd"; xethlool()tEul"el ol!) }; ) }; ) jsiegtn(.xct(; amn.eEv)eeue) hint: press F12 and paste this code!
  • 34. Own matchers bfrEc(ucin( { eoeahfnto ) ti.dMthr( hsadaces{ iAa:fnto ( { sCt ucin ) rtr ti.culiFuf( & ti.culiLz(; eun hsata.slfy) & hsata.say) } }; ) }; ) dsrb(Gril' fnto ( { ecie'afed, ucin ) i(i act,fnto ( { t's a' ucin ) epc(e Gril()iAa(; xetnw afed).sCt) }; ) }; ) » Documentation
  • 35. Test-Driven Development 1. Write your tests 2. Watch them fail 3. Make them pass 4. Refactor 5. Repeat see Growing Object-Oriented Software, Guidedorby Tests , page 6 see Working Effectively with Legacy Code , page 62 many other
  • 36. 1. Write your test dsrb(svFra" fnto ( { ecie"aeomt, ucin ) vroiia ='0 -{}-{}; a rgnl {} 1 2' i(sol rpaepaeodr" fnto ( { t"hud elc lchles, ucin ) vrepce =' -B-C; a xetd A ' vrfrae =svFra(rgnl '' '' ''; a omtd aeomtoiia, A, B, C) epc(omtd.oqa(xetd; xetfrae)tEulepce) }; ) i(sol ecd ijce cnet,fnto ( { t"hud noe netd otn" ucin ) vrepce =' -&tbg;ETl;bg;-C; a xetd A l;&tTS&t/&t ' vrfrae =svFra(rgnl '' 'bTS<b' ''; a omtd aeomtoiia, A, <>ET/>, C) epc(omtd.oqa(xetd; xetfrae)tEulepce) }; ) }; )
  • 37. 2. Watch them fail vrsvFra =fnto( { a aeomt ucin) rtr "o!; eun bo" }; jsiegtn(.xct(; amn.eEv)eeue) Demo
  • 38. 3. Make them pass vrsvFra =fnto(x){ a aeomt ucintt $agmns.ahfnto (,ie){ (ruet)ec(ucin i tm i ( >0 { f i ) ie =((<i/'.etie)hm() tm $'dv>)tx(tm.tl); tt=ttrpae""+( -1 +"" ie) x x.elc({ i ) }, tm; } }; ) rtr tt eun x; }; jsiegtn(.xct(; amn.eEv)eeue) Demo
  • 39. 4. Refactor fnto hmEcd(nu){ ucin tlnoeipt rtr ((<i/'.etipt.tl); eun $'dv>)tx(nu)hm() } vrsvFra =fnto(x){ a aeomt ucintt $ec(ruet,fnto (,ie){ .ahagmns ucin i tm i ( >0 { f i ) ie =hmEcd(tm; tm tlnoeie) tt=ttrpae""+( -1 +"" ie) x x.elc({ i ) }, tm; } }; ) rtr tt eun x; }; jsiegtn(.xct(; amn.eEv)eeue) Demo
  • 40. 5. Repeat fnto hmEcd(nu){ ucin tlnoeipt rtr ((<i/'.etipt.tl); eun $'dv>)tx(nu)hm() } vrsvFra =fnto( { a aeomt ucin) vrag =Arypooyesiecl(ruet) a rs ra.rttp.lc.alagmns; vrtt=ag.hf(; a x rssit) $ec(rs fnto (,ie){ .ahag, ucin i tm ie =hmEcd(tm; tm tlnoeie) tt=ttrpae""+i+"" ie) x x.elc({ }, tm; }; ) rtr tt eun x; }; jsiegtn(.xct(; amn.eEv)eeue) Demo
  • 41. Testing HTML Jasmine is DOM agnostic comes without tools to set up HTML fixtures Definition: A test fixture is a fixed state of a set of objects used as a baseline for running tests.
  • 42. First Solution in memory fixture with jQuery dsrb(tiiljur pui' fnto ( { ecie'rva Qey lgn, ucin ) vrfxue a itr; bfrEc(ucin( { eoeahfnto ) fxue=$'dvsm HM cd hr<dv'; itr (<i>oe TL oe ee/i>) }; ) i(sol d smtig,fnto ( { t'hud o oehn' ucin ) fxuemPui(; itr.ylgn) epc(itr)tHvCas"eCas) xetfxue.oaels(nwls"; }; ) }; ) jsiegtn(.xct(; amn.eEv)eeue) ... only works for trivial plugins!
  • 43. Clumsy Solution directly append to/remove from DOM dsrb(m jur pui' fnto ( { ecie'y Qey lgn, ucin ) bfrEc(ucin( { eoeahfnto ) $'fxue)rmv(; (#itr'.eoe) $'oy)apn(<i i=fxue>TL/i>) (bd'.ped'dv d"itr"HM<dv'; }; ) i(sol d smtig,fnto ( { t'hud o oehn' ucin ) $'fxue)mPui(; (#itr'.ylgn) epc((#itr')tHvCas"eCas) xet$'fxue).oaels(nwls"; }; ) }; ) jsiegtn(.xct(; amn.eEv)eeue)
  • 44. jasmine-jquery custom matchers , HTML/style/JSON fixtures, event spies dsrb(m jur pui' fnto ( { ecie'y Qey lgn, ucin ) bfrEc(ucin){ eoeahfnto( jsiegtitrs)fxuePt=j/_amn-eojur' amn.eFxue(.itrsah's5jsiedm_qey; jsiegtitrs)la(jur.ylgnse.tl) amn.eFxue(.od'qeymPui.pchm'; }; ) i(sol d smtig,fnto( { t'hud o oehn' ucin) vr$i =$'hlool'.ylgn) a dv (#elWrd)mPui(; epc(dv.oaels(nwls"; xet$i)tHvCas"eCas) }; ) }; ) jsiegtn(.xct(; amn.eEv)eeue) Demo
  • 46. Spies test behaviour dsrb(Gril' fnto ( { ecie'afed, ucin ) dsrb(we tl t b nc' fnto( { ecie'hn od o e ie, ucin) vrgril; a afed bfrEc(ucin){ eoeahfnto( gril =nwGril(; afed e afed) syngril,'oordenEtiz'.nClTruh) pO(afed gTFigAdaPza)adalhog(; }; ) i(sol ase wt o' fnto( { t'hud nwr ih k, ucin) vrase =gril.eie) a nwr afedbNc(; epc(nwr.oqa(o"; xetase)tEul"k) }; ) i(sol selpza,fnto ( { t'hud ta iz' ucin ) gril.eie) afedbNc(; epc(afedgTFigAdaPza.oaeenald) xetgril.oordenEtiz)tHvBeCle(; }; ) }; ) }; ) jsiegtn(.xct(; amn.eEv)eeue) A spy can stub any function and tracks calls to it and all arguments. Demo