Basics
Basics

 History
 Variable Type
 Statement Review
 Battle against Coding Horror



                                 Basics
History
 JavaScript – What a Dummy name nothing to do with
                        Java ! except the name & year of birthdate 1995
 Prefer the reference to EMACScript 5
                                                last revision in december 2009

 Suffering as Popup langage and unconsistence
                                     Comparing The « Grail » POO (Java / C++)

 New Dynamic from AJAX ( Web 2.0)
                                                          has become in 2007

 Recently NodeJS 2010 (JS on Server-Side)

                                                                        Basics
 Cloud (rich Client-Side apps)
Variable Type 1/2
 Boolean, Number, String, Date, Array, Object, Function, null,
undefined
                        var variable;
 undefined ?
Mutiple variable declaration at top of inner function
var variable1,
      variable2,
      variable2;


 Use simple quote as double quote to improve
consistent and readability                                   Basics
Variable Type 2/2
 Use JSON to improve consistence
var comment = {
      title: ‘my title’,
      date: new Date(),
      body: ‘my comment’
};
 Declare Array with [] and Object with {}
var comments = [];
comments.push(comment);
comments.render = function() {
      /* comments collection rendering */
}
                                                 Basics
Prefer Declare function with = function() { }
Use delete keyword to delete variable
Statement Review
 Use coding style
    functionNamesLikeThis;
    variableNamesLikeThis;
    ConstructorNamesLikeThis;
    EnumNamesLikeThis;
    methodNamesLikeThis;
    SYMBOLIC_CONSTANTS_LIKE_THIS;
                                                     extract from Google Closure Library Style Guide
 Always put brachet on statement and space on test
         if ( test ) {
                  /* something to do */
         }

 Forget eval function you are going wrong !

 Max 3 level of indentation otherwise it means you are going wrong
                                                              extract from Linux Kernel Coding Style
 Strip whitespace and always use 4 spaces as tab spacing
 Use triple equality test === to avoid implicit type coercion                       Basics
Battle against Coding Horror
 Split big JS file into multiples files

 name your file regarding the namespace
/namespace/namespace.Class.js

 Use Namespace Pattern to group your Classes & Object
Instances

var namespace = namespace || {};
namespace.instance = new namespace.Class;

 Max target size of lines should be lower than 250
                                                         Basics
Let’s go

 Decide to look code around you and try
to apply 3 recommandations a week
 Have Fun !


                To be continue… Fundamental JS

                                          Basics

JS - Basics

  • 1.
  • 2.
    Basics  History  VariableType  Statement Review  Battle against Coding Horror Basics
  • 3.
    History  JavaScript –What a Dummy name nothing to do with Java ! except the name & year of birthdate 1995  Prefer the reference to EMACScript 5 last revision in december 2009  Suffering as Popup langage and unconsistence Comparing The « Grail » POO (Java / C++)  New Dynamic from AJAX ( Web 2.0) has become in 2007  Recently NodeJS 2010 (JS on Server-Side) Basics  Cloud (rich Client-Side apps)
  • 4.
    Variable Type 1/2 Boolean, Number, String, Date, Array, Object, Function, null, undefined var variable;  undefined ? Mutiple variable declaration at top of inner function var variable1, variable2, variable2;  Use simple quote as double quote to improve consistent and readability Basics
  • 5.
    Variable Type 2/2 Use JSON to improve consistence var comment = { title: ‘my title’, date: new Date(), body: ‘my comment’ };  Declare Array with [] and Object with {} var comments = []; comments.push(comment); comments.render = function() { /* comments collection rendering */ } Basics Prefer Declare function with = function() { } Use delete keyword to delete variable
  • 6.
    Statement Review  Usecoding style functionNamesLikeThis; variableNamesLikeThis; ConstructorNamesLikeThis; EnumNamesLikeThis; methodNamesLikeThis; SYMBOLIC_CONSTANTS_LIKE_THIS; extract from Google Closure Library Style Guide  Always put brachet on statement and space on test if ( test ) { /* something to do */ }  Forget eval function you are going wrong !  Max 3 level of indentation otherwise it means you are going wrong extract from Linux Kernel Coding Style  Strip whitespace and always use 4 spaces as tab spacing  Use triple equality test === to avoid implicit type coercion Basics
  • 7.
    Battle against CodingHorror  Split big JS file into multiples files  name your file regarding the namespace /namespace/namespace.Class.js  Use Namespace Pattern to group your Classes & Object Instances var namespace = namespace || {}; namespace.instance = new namespace.Class;  Max target size of lines should be lower than 250 Basics
  • 8.
    Let’s go  Decideto look code around you and try to apply 3 recommandations a week  Have Fun ! To be continue… Fundamental JS Basics