SlideShare une entreprise Scribd logo
09/06/2016
Formation JavaScript avancé alphorm.com™©
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
avancé
JavaScript,
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Présentation du formateur
• Les autres formations sur Alphorm
• Le plan de formation
• Présentation des outils
• Les publics concernés
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Présentation du formateur
• Les autres formations sur Alphorm
• Le plan de formation
• Présentation des outils
• Les publics concernés
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les autres formations sur Alphorm
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le plan de formation
• Présentation de la formation
• Utilisation avancée des Fonctions
• Programmation Orienté Objet en JavaScript
• Programmation asynchrones
• Les tasks runner
• Programmation Modulaire
• Le futur de JavaScript
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le plan de formation
• Présentation de la formation
• Utilisation avancée des Fonctions
• Programmation Orienté Objet en JavaScript
• Programmation asynchrones
• Les tasks runner
• Programmation Modulaire
• Le futur de JavaScript
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation des outils
Les éditeurs
• SublimeText
• Atom
• Microsoft Visual Studio Code
• NotePad++
• jsfiddle.net
Les navigateurs
• Chrome
• Firefox
• Internet Explorer
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les publics concernés
• Les développeurs et chefs de projets qui souhaitent approfondir leurs
connaissances de JavaScript.
09/06/2016
Formation JavaScript avancé alphorm.com™©
JavaScript Avancé
C’est parti !
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les différents types de fonction
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Utilisation avancée des Fonctions
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Rappel sur les fonctions
• Les fonctions anonymes
• Les fonctions callbacks
• Les fonctions immédiates
• Les fonctions internes
• Les scopes
• Les closures
09/06/2016
Formation JavaScript avancé alphorm.com™©
Rappel sur les fonctions
• Les fonctions permettent de factoriser du code pour permettre une
réutilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions anonymes
• Une fonction anonyme est une fonction qui n’a pas de nom
• Très peu utilisée de cette façon, on préfère :
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions callbacks
• Les fonctions sont typées comme des variables
• On peut donc les passer en paramètre
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions immédiates (Self-invoking)
• Les fonctions immédiates sont une application des fonctions anonymes,
mais appelées directement après leurs créations
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions internes (Inner)
• Les fonctions sont typées comme des variables
• On peut donc les déclarer dans une fonction comme de simples
variables
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les scopes
http://www.basing.com/books/javascript/how-variable-scope-works-in-javascript/2
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les closures
http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/what-is-closure-in-javascript/
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Rappel sur les fonctions
• Les principales structures de fonctions
• Rapide présentation des scopes et closures
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions anonymes
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Utilisation avancée des Fonctions
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Les fonctions anonymes
• Exemple
• Mise en situation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions anonymes
• Structure fondamentale
• Elles permettent d’isoler des variables dans un contexte local
• Elles permettent de simuler un namespace ou packages
09/06/2016
Formation JavaScript avancé alphorm.com™©
Examples
• Déclaration de base :
• Mais peu pratique alors on stocke dans une variable :
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation
• Première approche pour la réalisation d’un namespace ou package
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation du formateur
Frédéric GAURAT
Développeur et formateur indépendant
• Compétences
Web Front : HTML5/CSS3, JavaScript, Angular
Web Back : PHP, Symfony, CakePHP, JEE
Mobile : Android, Cordova/PhoneGap/Ionic
• Mes références
Site : www.eolem.com
Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation du formateur
Frédéric GAURAT
Développeur et formateur indépendant
• Compétences
Web Front : HTML5/CSS3, JavaScript, Angular
Web Back : PHP, Symfony, CakePHP, JEE
Mobile : Android, Cordova/PhoneGap/Ionic
• Mes références
Site : www.eolem.com
Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation du formateur
Frédéric GAURAT
Développeur et formateur indépendant
• Compétences
Web Front : HTML5/CSS3, JavaScript, Angular
Web Back : PHP, Symfony, CakePHP, JEE
Mobile : Android, Cordova/PhoneGap/Ionic
• Mes références
Site : www.eolem.com
Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation du formateur
Frédéric GAURAT
Développeur et formateur indépendant
• Compétences
Web Front : HTML5/CSS3, JavaScript, Angular
Web Back : PHP, Symfony, CakePHP, JEE
Mobile : Android, Cordova/PhoneGap/Ionic
• Mes références
Site : www.eolem.com
Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation du formateur
Frédéric GAURAT
Développeur et formateur indépendant
• Compétences
Web Front : HTML5/CSS3, JavaScript, Angular
Web Back : PHP, Symfony, CakePHP, JEE
Mobile : Android, Cordova/PhoneGap/Ionic
• Mes références
Site : www.eolem.com
Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation
• CallBack et contexte d’exécution
Mauvaise méthode Bonne méthode
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Les fonctions callbacks
• Un exemple simple d’utilisation
• Mise en situation pratique qui intègre une fonction anonyme
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions immédiates
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Utilisation avancée des Fonctions
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Les fonctions immédiates
• Exemple
• Mise en situation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions immédiates (Self-invoking)
• Autre cas d’utilisation des fonctions anonymes
• Permet la limitation de la portée des variables tout en
exécutant du code
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Fonction anonyme normale :
• Fonction anonyme auto-appelée :
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation
• Fonction immédiate avec passage de paramètre
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Les fonctions immédiates
• Exemple simple
• Mise en situation d’une fonction immédiate avec passage de paramètre
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions internes
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Utilisation avancée des Fonctions
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Les fonctions internes
• Exemple
• Mise en situation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les fonctions internes (Inner)
• Les fonctions sont des variables typées donc stockables
dans une fonction !
• Elle peuvent servir pour déclarer des fonctions privées
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Dans cet exemple MultPar2 n’est pas accessible.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation
• Cas d’une fonction interne renvoyée par un return
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Les fonctions internes
• Un exemple simple
• Cas d’un retour de fonction
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les Scopes
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Utilisation avancée des Fonctions
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Les scopes
• Exemple
• Mise en situation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les scopes
• En JavaScript, les portées sont définies par des fonctions et
seulement par des fonctions
• Le « hoisting » vous assure qu’une variable déclarée tard
dans le code sera remontée dans sa portée.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Différences de portée de variable
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation
• Le hoisting
• Dans ce cas ‘var b’ est remonté
• La syntaxe use-strict impose une rigueur de codage (utilisation de ‘var’
obligatoire par exemple)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation (suite)
• Le hoisting
• Dans ce cas ‘var b’ est remonté mais pas b=2, le résultat est NaN
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation (suite)
• Le hoisting pour les fonctions
• Pas d’erreurs dans Chrome, en revanche ça ne fonctionne pas dans
Firefox
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Les scopes, le hoisting
• Exemple
• Mise en situation du hoisting sur variables et fonctions
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les closures
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Utilisation avancée des Fonctions
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Les closures
• Exemple
• Mise en situation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les closures
• La notion de closure est associée à la notion de portée de variable
• Une variable est « enfermée » dans sa fonction ( sa portée)
• Une fonction définie dans la même fonction (portée) va se « souvenir »
de cette variable
https://developer.mozilla.org/fr/docs/Web/JavaScript/Closures
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les closures
• afficheNom() va se souvenir de la variable ‘nom’ déclarée dans la
portée.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Mise en situation
• Ici, on stocke un tableau contenant le nom des jours.
• Dans ce cas le tableau n’est créé qu’une seule fois, pas de multiplication
de ce tableau en mémoire
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les autres formations sur Alphorm
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les autres formations sur Alphorm
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les autres formations sur Alphorm
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les autres formations sur Alphorm
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les autres formations sur Alphorm
09/06/2016
Formation JavaScript avancé alphorm.com™©
Des tableaux aux objets (suite)
• JavaScript ne supporte pas les tableaux associatifs
• Pour implémenter un tableau associatif, on passe par un objet :
09/06/2016
Formation JavaScript avancé alphorm.com™©
Accès aux propriétés
• On utilise la notation « pointée »
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Rappel sur les objets en JavaScript
• Comparaison des syntaxes des tableaux et des objets
• L’accès aux propriétés
09/06/2016
Formation JavaScript avancé alphorm.com™©
Rappel sur les prototypes
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
POO en JavaScript
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Présentation de la notion de prototype
•Exemples
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de la notion de prototype
• En JavaScript, chaque objet à un prototype
• Le prototype est une propriété de cet objet
• Le prototype lui-même est un objet
• Tous les objets JavaScript héritent leurs méthodes de leurs
prototypes
09/06/2016
Formation JavaScript avancé alphorm.com™©
Notation litéral
• La propriété __proto__ donne un accès au prototype de l’objet
09/06/2016
Formation JavaScript avancé alphorm.com™©
Notation avec constructeur
• Peu importe la façon de créer l’objet (littéral ou avec constructeur)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ajout de propriétés et de méthodes
• JavaScript est dynamique, on peut ajouter des méthodes après
déclaration et instanciation de l’objet.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ajout de propriétés et de méthodes (suite)
• En ajoutant propriétés et méthodes sur le prototype c’est l’ensemble
des objets qui en bénéficient
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Présentation de la notion de prototype
• Ajout de propriétés et méthodes sur un objet
• Ajout de propriétés et méthodes sur le prototype d’un objet
09/06/2016
Formation JavaScript avancé alphorm.com™©
Implémentation
des constructeurs
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
POO en JavaScript
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Présentation des fonctions comme constructeur d’objet
• La propriété constructor
• Exemples
09/06/2016
Formation JavaScript avancé alphorm.com™©
Fonctions comme constructeur d’objet
• JavaScript n’a pas de notion de classe.
• Pour construire un objet on passe par une fonction
constructeur
• Le constructeur est appelé au moment de l’instanciation et
toutes les opérations qui y sont déclarées sont exécutées
09/06/2016
Formation JavaScript avancé alphorm.com™©
La propriété constructor
• La propriété constructor renvoie la référence à la fonction
utilisée pour créer le prototype de l’instance
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Utilisation d’un constructeur
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Affichage de la fonction utilisée pour construire l’objet
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Modifier un constructeur en utilisant la propriété constructor
• En réalité on ne change pas le constructeur mais seulement ce que
renvoie la propriété constructor (il ne faut pas se fier à ce que renvoie
constructor)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• L’utilisation des fonctions constructeurs
• La propriété constructor
09/06/2016
Formation JavaScript avancé alphorm.com™©
Implémentation
de l’encapsulation
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
POO en JavaScript
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Encapsuler des propriétés et méthodes
• Simuler les propriétés et méthodes publics
• Simuler les propriétés et méthodes privates
09/06/2016
Formation JavaScript avancé alphorm.com™©
Encapsuler des propriétés et méthodes
• JavaScript ne dispose pas de moyens pour déclarer des
propriétés ou méthodes public, private ou protected
• Pour simuler ce comportement nous allons exploiter le
comportement normal de la déclaration de variable
09/06/2016
Formation JavaScript avancé alphorm.com™©
Simuler les propriétés et méthodes publics
• Pour déclarer des méthodes ou propriétés public ou utilise « this »
09/06/2016
Formation JavaScript avancé alphorm.com™©
Simuler les propriétés et méthodes privates
• Pour déclarer des méthodes ou propriétés privates ou utilise « var »
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Les moyens de simuler les « privates » et « public » que l’on
trouve dans d’autres langages.
09/06/2016
Formation JavaScript avancé alphorm.com™©
L’héritage
en JavaScript
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
POO en JavaScript
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Implémenter l’héritage en JavaScript
•Exemples
09/06/2016
Formation JavaScript avancé alphorm.com™©
Implémenter l’héritage en JavaScript
• L’héritage permet de créer des objets spécialisés à partir d’un autre
objet. JavaScript s’appuie sur l’héritage unique.
• Pour implémenter l’héritage, on assigne une instance de l’objet parent à
la propriété prototype de l’objet fils.
• On parle donc d’héritage de prototype et de « prototype chain »
• Pour éviter que le constructeur soit celui du parent on réassigne le
constructeur à l’enfant.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple d’héritage
obj1
obj2
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple d’héritage
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•La notion d’héritage de prototype en JavaScript
09/06/2016
Formation JavaScript avancé alphorm.com™©
Utilisation du « this »
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
POO en JavaScript
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Définition et utilisation de « this »
•Exemples
09/06/2016
Formation JavaScript avancé alphorm.com™©
Définition et utilisation de « this »
• Le « this » est une référence à un objet (une fonction en JavaScript)
• La valeur de this est déterminée par la façon dont on appelle la
fonction.
• Dans le contexte global : this fait référence à l’objet global
09/06/2016
Formation JavaScript avancé alphorm.com™©
Dans un contexte de fonction
• En mode non strict, this n’étant pas défini il prend l’objet global
• En mode strict, this n’étant pas défini il la valeur undefined
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
Avancé
DART
Tests
Unitaires
JavaScript,
les fondamentaux
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•La définition d’un callback hell
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les Promesses
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Programmation asynchrones
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Définition d’une promesse
•Exemples
09/06/2016
Formation JavaScript avancé alphorm.com™©
Définition d’une promesse
• Une promesse est utilisée pour réaliser des opérations asynchrone.
• Elle peut être dans un de ces états :
en attente : état initial, la promesse n'est ni remplie, ni rompue
tenue : l'opération a réussi
rompue : l'opération a échoué
acquittée : la promesse est tenue ou rompue mais elle n'est plus en attente.
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Nous souhaitons faire la somme de 2 entiers.
• Ces entiers seront calculés plus tard (on simule une requête serveur)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple du callback hell
• Pour synchroniser les traitements nous exécuterons les
traitements l’un après l’autre.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple avec des promesses
• Etape 1 : on créée un objet Promise
• Etape 2 : on attend que la promesse soit tenue (resolve) avec la
méthode then
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple avec des promesses
• Pour synchroniser les 2 traitements :
Lorsqu’une promesse est résolue on enchaîne avec l’autre
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple avec des promesses
• Pour synchroniser les traitements on peut passer par la méthode all()
qui reçoit un tableau de promesses et qui sera résolue lorsque toutes
les promesses du tableau le seront.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• Le fonctionnement et l’utilisation des promesses
• Un exemple d’utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation et tâches
de base
Les tasks runner
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Les besoins des développeurs JavaScript
•Les outils
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les besoins des développeurs JavaScript
JavaScript
Qualité du code
Minification
Production
CSS
Préprocesseur
LESS/Sass
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les outils
• Exécuteurs de tâches
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•L’intérêts d’utiliser des exécuteurs de tâches
•Les principaux outils
09/06/2016
Formation JavaScript avancé alphorm.com™©
GruntJS
Les tasks runner
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
Frédéric GAURAT
Développeur et Formateur
Consultant indépendant
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Présentation de GruntJS
•Utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
GruntJS
• GruntJS est un exécuteur de tâches
• Il s’appuie sur des plugins
• Ainsi que sur un fichier (GruntFile) pour configurer les plugins
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le plan de formation
• Présentation de la formation
• Utilisation avancée des Fonctions
• Programmation Orienté Objet en JavaScript
• Programmation asynchrones
• Les tasks runner
• Programmation Modulaire
• Le futur de JavaScript
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le plan de formation
• Présentation de la formation
• Utilisation avancée des Fonctions
• Programmation Orienté Objet en JavaScript
• Programmation asynchrones
• Les tasks runner
• Programmation Modulaire
• Le futur de JavaScript
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le fichier Gruntfile.js
• Structure de base
09/06/2016
Formation JavaScript avancé alphorm.com™©
Configuration d’un plugin
• Chargement du plugin
• Enregistrement de la tâche
09/06/2016
Formation JavaScript avancé alphorm.com™©
Configuration d’un plugin (suite)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
• L’exécuteur de tâche GruntJS
• L’installation
• L’installation et la configuration d’un plugin
09/06/2016
Formation JavaScript avancé alphorm.com™©
Frédéric GAURAT
Formateur et Consultant indépendant
Ingénierie statistique et financière
GulpJS
Les tasks runner
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Présentation de GulpJS
•Utilisation de GulpJS
09/06/2016
Formation JavaScript avancé alphorm.com™©
GulpJS
• GulpJS est un exécuteur de tâches
• Il s’appuie sur des plugins
• Ainsi que sur un fichier (gulpfile.js) pour configurer les
plugins
• Il se diffère de GruntJS dans son mode de fonctionnement :
Grunt s’appuie sur des fichiers pour la réalisation des tâches
GulpJS s’appuie sur des streams (des fluxs entre les tâches)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Installation
•L’installation se fait avec l’utilitaire npm
09/06/2016
Formation JavaScript avancé alphorm.com™©
Installation d’un plugin
• Pour une tâche de minification le plugin est uglify
http://gulpjs.com/plugins/ pour la totalité des plugins
https://www.npmjs.com/package/gulp-uglify/ pour le plugin uglify
• Installation du plugin
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le plan de formation
• Présentation de la formation
• Utilisation avancée des Fonctions
• Programmation Orienté Objet en JavaScript
• Programmation asynchrones
• Les tasks runner
• Programmation Modulaire
• Le futur de JavaScript
09/06/2016
Formation JavaScript avancé alphorm.com™©
Configuration d’un plugin
• Installation du plugin
• Chargement du plugin
• Enregistrement de la tâche
09/06/2016
Formation JavaScript avancé alphorm.com™©
Configuration d’un plugin (suite)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•L’exécuteur de tâche GulpJS
•L’installation
•L’installation et la configuration d’un plugin
09/06/2016
Formation JavaScript avancé alphorm.com™©
Frédéric GAURAT
Formateur et Consultant indépendant
Ingénierie statistique et financière
Organiser son code
et le rendre performant
Programmation modulaire
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
• Introduction à la programmation modulaire
• Rappel sur le pattern Module
• Les problèmes et les solutions
09/06/2016
Formation JavaScript avancé alphorm.com™©
La programmation modulaire
• En JavaScript il n’y a pas d’instruction pour créer des
modules
• Il faut utiliser le pattern module
• Il n’y a pas de gestion de dépendance
• L’ensemble des scripts doivent être chargés au démarrage
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le pattern module
• Le pattern module permet d’encapsuler du code comme un
package ou namespace
• Il s’appuie sur une « Anonymous Closure »
Permet la déclaration de variable privée
Permet de maintenir l’état des variables
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le pattern module (suite)
• Anonymous Closure
• Ajout d’une dépendance
09/06/2016
Formation JavaScript avancé alphorm.com™©
Le pattern module (suite)
• Module export
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les problèmes
• Les modules sont des unités de code indépendant les uns
des autres
• Ils sont stockés dans des fichiers distincts
• Difficile de gérer les dépendances
• Difficile de charger les fichiers au bon moment
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les solutions
• Asynchronous module definition (AMD)
Spécification JavaScript
Définit une API pour décrire des modules, gérer leurs dépendances et les
charger dynamiquement (éventuellement)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•La programmation modulaire
•Le pattern module
•La spécification AMD
09/06/2016
Formation JavaScript avancé alphorm.com™©
Frédéric GAURAT
Formateur et Consultant indépendant
Ingénierie statistique et financière
Utilisation de RequireJS
Programmation Modulaire
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Présentation de RequireJS
•Utilisation de RequireJS
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de RequireJS
•RequireJS est un outil permettant le chargement de
fichiers et de modules JavaScript
•http://requirejs.org/
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation des outils
Les éditeurs
• SublimeText
• Atom
• Microsoft Visual Studio Code
• NotePad++
• jsfiddle.net
Les navigateurs
• Chrome
• Firefox
• Internet Explorer
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation des outils
Les éditeurs
• SublimeText
• Atom
• Microsoft Visual Studio Code
• NotePad++
• jsfiddle.net
Les navigateurs
• Chrome
• Firefox
• Internet Explorer
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation des outils
Les éditeurs
• SublimeText
• Atom
• Microsoft Visual Studio Code
• NotePad++
• jsfiddle.net
Les navigateurs
• Chrome
• Firefox
• Internet Explorer
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation des outils
Les éditeurs
• SublimeText
• Atom
• Microsoft Visual Studio Code
• NotePad++
• jsfiddle.net
Les navigateurs
• Chrome
• Firefox
• Internet Explorer
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation des outils
Les éditeurs
• SublimeText
• Atom
• Microsoft Visual Studio Code
• NotePad++
• jsfiddle.net
Les navigateurs
• Chrome
• Firefox
• Internet Explorer
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation des outils
Les éditeurs
• SublimeText
• Atom
• Microsoft Visual Studio Code
• NotePad++
• jsfiddle.net
Les navigateurs
• Chrome
• Firefox
• Internet Explorer
09/06/2016
Formation JavaScript avancé alphorm.com™©
Installation
• Le compilateur s’installe via npm :
• Il est possible de tester directement en ligne sur le site :
http://coffeescript.org/ (‘Try Coffeescript’)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Utilisation
• Appel de fonction
• Déclaration de fonction
09/06/2016
Formation JavaScript avancé alphorm.com™©
Utilisation
• Déclaration de fonction (suite)
• Déclaration de variable et portée lexicale
09/06/2016
Formation JavaScript avancé alphorm.com™©
Utilisation
• Les boucles
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•Une introduction à CoffeeScript
•Quelques exemples d’utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Frédéric GAURAT
Formateur et Consultant indépendant
Ingénierie statistique et financière
Dart
Le Futur de JavaScript
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Présentation de Dart
•Utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de Dart
• Langage de développement web (objet) proposé par Google
• Il a vocation à remplacer le JavaScript
• Pour le moment il permet d’obtenir du JavaScript après compilation
• Il peut tourner dans une VM côté serveur
• Il est testable en ligne : https://dartpad.dartlang.org
• Contrairement aux autres outils, il ne s’installe pas avec npm
• https://www.dartlang.org/downloads/
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
• Exemple HelloWorld
09/06/2016
Formation JavaScript avancé alphorm.com™©
Déclaration de variable
• Il est possible d’annoter les variables avec un type
09/06/2016
Formation JavaScript avancé alphorm.com™©
Déclaration de fonction
• Les type s’appliquent aussi aux fonctions et les déclarations
sont soumises au compilateur
09/06/2016
Formation JavaScript avancé alphorm.com™©
Les publics concernés
• Les développeurs et chefs de projets qui souhaitent approfondir leurs
connaissances de JavaScript.
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•Une introduction à Dart
•Quelques exemples d’utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Frédéric GAURAT
Formateur et Consultant indépendant
Ingénierie statistique et financière
TypeScript
Le Futur de JavaScript
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Présentation de TypeScript
•Exemples d’utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de TypeScript
• TypeScript est un langage développé par Microsoft
• Il a pour but d’améliorer la production de code JavaScript
• Il intègre JavaScript (JavaScript est utilisable dans TypeScript)
• Il a été utilisé pour le développement d’Angular 2.
• Il est testable en ligne : http://www.typescriptlang.org/play/index.html
09/06/2016
Formation JavaScript avancé alphorm.com™©
Installation et utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Exemple
•Les variables sont typées
09/06/2016
Formation JavaScript avancé alphorm.com™©
Déclaration de class
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert
•Présentation de TypeScript
•Quelques exemples d’utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Frédéric GAURAT
Formateur et Consultant indépendant
Ingénierie statistique et financière
ECMAScript6
Le Futur de JavaScript
Site : http://www.alphorm.com
Blog : http://blog.alphorm.com
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Présentation de ECMA
•Présentation de ECMAScript6
•Exemples d’utilisation
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de ECMA
• ECMA (European Computer Manufacturers Association) est
une organisation de standardisation.
• Elle est à l’origine des standards pour Dart (ECMA-408)
• ECMAScript (ECMA-262) mis en œuvre dans : ActionScript
(Adobe), JavaScript, C++ (norme 2011).
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de ECMAScript6
• Aussi nommée ECMSScript 2015 (sortie en Juin 2015)
• N’est pas encore supporté par les navigateurs du moment.
• Il est possible de passer par transcompilateur (compilateur
de source à source) pour transformer l’ECMAScript6 en
ECMAScript5 avec http://babeljs.io/
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de ECMAScript6 (suite)
• Portée de variable avec let
• Template String
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de ECMAScript6 (suite)
• Paramètre de fonction par défaut
• Les Lambdas (Arrow function)
09/06/2016
Formation JavaScript avancé alphorm.com™©
Présentation de ECMAScript6 (suite)
• Les classes et héritage
09/06/2016
Formation JavaScript avancé alphorm.com™©
JavaScript Avancé
C’est parti !
09/06/2016
Formation JavaScript avancé alphorm.com™©
JavaScript Avancé
C’est parti !
09/06/2016
Formation JavaScript avancé alphorm.com™©
Plan
•Ce qui a été couvert
•Ce qui reste à aborder
09/06/2016
Formation JavaScript avancé alphorm.com™©
Ce qu’on a couvert dans cette formation
• Présentation de la formation
Présentation de la formation
• Utilisation avancée des Fonctions
Les différents types de fonction (anonymes, callback,
immédiates, internes)
Les scopes et les closures
• Programmation Orienté Objet en JavaScript
Rappel sur les objets et prototypes
Implémentation des constructeurs
Implémentation de l’encapsulation
L’héritage en JavaScript
Utilisation du « this »
• Programmation asynchrones
Le callback hell
Les promesses
• Les tasks runner
Les tâches de base (Qualité,Obfuscation,…)
Présentation de Grunt et Gulp
• Programmation Modulaire
Organiser son code et le rendre performant :
Asynchronous Module Definition (AMD)
Utilisation de RequireJS
• Le futur de JavaScript
CoffeeScript / Dart / TypeScript
La spécification ECMAScript 6
09/06/2016
Formation JavaScript avancé alphorm.com™©
Cursus formations JavaScript
JavaScript,
les fondamentaux
DART
Tests
Unitaires
JavaScript,
Avancé
CoffeeScript
Tests
fonctionnels
TypeScript
AngularJS 2,
les fondamentaux
AngularJS 2,
Avancé
09/06/2016
Formation JavaScript avancé alphorm.com™©
A bientôt !
Site : www.eolem.com
Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat

Contenu connexe

PDF
Alphorm.com Formation knockoutJS
PDF
Alphorm.com Support de la formation JavaScript les fondamentaux
PDF
Alphorm.com Support de la Formation Sketchup 2016, Perfectionnement
PDF
Alphorm.com Formation NodeJS, les fondamentaux
PDF
Alphorm.com Support de la formation NodeJS , avancé
PDF
Alphorm.com Formation Windev 20 Pefectionnement
PDF
Alphorm.com Formation Le Language C
PDF
Alphorm.com Formation jQuery
Alphorm.com Formation knockoutJS
Alphorm.com Support de la formation JavaScript les fondamentaux
Alphorm.com Support de la Formation Sketchup 2016, Perfectionnement
Alphorm.com Formation NodeJS, les fondamentaux
Alphorm.com Support de la formation NodeJS , avancé
Alphorm.com Formation Windev 20 Pefectionnement
Alphorm.com Formation Le Language C
Alphorm.com Formation jQuery

Tendances (20)

PDF
Alphorm.com Formation MS Project 2013
PDF
Alphorm.com Formation Dreamweaver CC pour les débutants
PDF
Alphorm.com Formation WordPress 4
PDF
Alphorm.com Support Formation Android 6, Expert
PDF
alphorm.com - Formation Microsoft PowerPoint 2013 (77-422)
PDF
alphorm.com - Formation XenSources
PDF
Alphorm.com - Formation programmer en Visual Basic .NET
PDF
alphorm.com - Formation Développez des applications Web avec ASP.NET MVC 4(70...
PDF
Alphorm.com-Formation windows phone 8.1
PDF
Formation Windev 19,les fondamentaux
PDF
Alphorm.com Support de la Formation CATIA V5 , les fondamentaux
PDF
Alphorm.com Java 8: les nouveautés
PDF
Alphorm.com Formation JavaFX
PDF
Alphorm.com Formation VMware Workstation 11
PDF
Alphorm.com Support de la Formation Azure IAAS avancé 1
PDF
alphorm.com - Formation Programmer en C++
PDF
alphorm.com - Formation UML
PDF
Alphorm.com support de la formation ms azure pour les développeurs
PDF
Alphorm.com Support de la Formation VMmware vSphere 6, La gestion du stockage
PDF
Alphorm.com Support de la Formation Microsoft Identity Manager (MIM) 2016 Imp...
Alphorm.com Formation MS Project 2013
Alphorm.com Formation Dreamweaver CC pour les débutants
Alphorm.com Formation WordPress 4
Alphorm.com Support Formation Android 6, Expert
alphorm.com - Formation Microsoft PowerPoint 2013 (77-422)
alphorm.com - Formation XenSources
Alphorm.com - Formation programmer en Visual Basic .NET
alphorm.com - Formation Développez des applications Web avec ASP.NET MVC 4(70...
Alphorm.com-Formation windows phone 8.1
Formation Windev 19,les fondamentaux
Alphorm.com Support de la Formation CATIA V5 , les fondamentaux
Alphorm.com Java 8: les nouveautés
Alphorm.com Formation JavaFX
Alphorm.com Formation VMware Workstation 11
Alphorm.com Support de la Formation Azure IAAS avancé 1
alphorm.com - Formation Programmer en C++
alphorm.com - Formation UML
Alphorm.com support de la formation ms azure pour les développeurs
Alphorm.com Support de la Formation VMmware vSphere 6, La gestion du stockage
Alphorm.com Support de la Formation Microsoft Identity Manager (MIM) 2016 Imp...
Publicité

En vedette (20)

PDF
Alphorm.com Formation Docker (1/2) : Installation et Administration
PDF
Alphorm.com Formation Angular : Avancé
PDF
Alphorm.com Formation TypeScript
PDF
Alphorm.com Formation Docker (2/2) - Administration Avancée
PDF
Alphorm.com Formation Microsoft Hyperconvergence
PDF
alphorm.com - Formation VMware Mirage 3.6
PDF
Alphorm.com Formation Lync Server 2013 (70-336)
PDF
Alphorm.com Support de la Formation Windows 10 Troubleshootings partie 1
PDF
Alphorm.com Formation Azure Active Directory RMS et Azure Information Protection
PDF
Alphorm.com-Formation windows 2012 (70-410)
PDF
Alphorm.com Formation Red Hat RH124
PDF
Alphorm.com Formation RDS Windows Server 2012 R2
PDF
Alphorm.com Formation OS X 10.11 Server El Capitan, Les fondamentaux
PDF
Alphorm.com Formation Oracle 12c DBA2 : Installation et mise à niveau
PDF
Alphorm.com Formation Autodesk Revit 2018 : L'essentiel
PDF
Alphorm.com Formation Les solutions de Haute Disponibilité sous Windows Serv...
PDF
Alphorm.com Formation SCCM 2012 R2
PDF
alphorm.com - Formation Windows 8.1 (70-688)
PDF
Alphorm.com Support de la formation Hacking & Sécurité, Expert - Vulnérabilit...
PDF
alphorm.com - Formation Exchange Server 2013 (70-341)
Alphorm.com Formation Docker (1/2) : Installation et Administration
Alphorm.com Formation Angular : Avancé
Alphorm.com Formation TypeScript
Alphorm.com Formation Docker (2/2) - Administration Avancée
Alphorm.com Formation Microsoft Hyperconvergence
alphorm.com - Formation VMware Mirage 3.6
Alphorm.com Formation Lync Server 2013 (70-336)
Alphorm.com Support de la Formation Windows 10 Troubleshootings partie 1
Alphorm.com Formation Azure Active Directory RMS et Azure Information Protection
Alphorm.com-Formation windows 2012 (70-410)
Alphorm.com Formation Red Hat RH124
Alphorm.com Formation RDS Windows Server 2012 R2
Alphorm.com Formation OS X 10.11 Server El Capitan, Les fondamentaux
Alphorm.com Formation Oracle 12c DBA2 : Installation et mise à niveau
Alphorm.com Formation Autodesk Revit 2018 : L'essentiel
Alphorm.com Formation Les solutions de Haute Disponibilité sous Windows Serv...
Alphorm.com Formation SCCM 2012 R2
alphorm.com - Formation Windows 8.1 (70-688)
Alphorm.com Support de la formation Hacking & Sécurité, Expert - Vulnérabilit...
alphorm.com - Formation Exchange Server 2013 (70-341)
Publicité

Similaire à Alphorm.com Support de la Formation JavaScript , avancé (20)

PPT
Introduction à JavaScript
PPTX
Cours javascript v1
PDF
Cours JavaScript
PDF
Notions de base de JavaScript
PDF
web-avance-jssvghjjjjjjkkkkhjjjjjkrtyujj
PPTX
Introduction à JavaScript
PDF
732587539-cours-tp-JavaScript-3Sfffffffffffffffffffffffffffffffffffffffffffff...
PPT
cours baser sur les bases de JAVASCRIPT.ppt
PDF
JavaScript pour débutant - toutes les notions de base
PDF
JavaScript pour le développeur Java
PDF
La programmation fonctionnelle en javascript / PF
PPTX
javascript cours developpement nbhdjcbhdcjbn
PDF
Johnny-Five : Robotique et IoT en JavaScript
PDF
Javascript
PDF
Fondamentaux portée - contexte - function ms tech days
PPTX
JavaScript prise en main et fondamentaux
PPTX
Javascript un langage supérieur
PDF
Javascript Json artchitecture
PDF
Partie1 TypeScript
ODP
Introduction à JavaScript
Introduction à JavaScript
Cours javascript v1
Cours JavaScript
Notions de base de JavaScript
web-avance-jssvghjjjjjjkkkkhjjjjjkrtyujj
Introduction à JavaScript
732587539-cours-tp-JavaScript-3Sfffffffffffffffffffffffffffffffffffffffffffff...
cours baser sur les bases de JAVASCRIPT.ppt
JavaScript pour débutant - toutes les notions de base
JavaScript pour le développeur Java
La programmation fonctionnelle en javascript / PF
javascript cours developpement nbhdjcbhdcjbn
Johnny-Five : Robotique et IoT en JavaScript
Javascript
Fondamentaux portée - contexte - function ms tech days
JavaScript prise en main et fondamentaux
Javascript un langage supérieur
Javascript Json artchitecture
Partie1 TypeScript
Introduction à JavaScript

Plus de Alphorm (20)

PDF
Alphorm.com Formation Microsoft 365 (MS-500) : Administrateur Sécurité - Prot...
PDF
Alphorm.com Formation Google Sheets : Créer un Tableau de Bord Collaboratif a...
PDF
Alphorm.com Formation CCNP ENCOR 350-401 (6of8) : Sécurité
PDF
Alphorm.com Formation Vue JS 3 : Créer une application de A à Z
PDF
Alphorm.com Formation Blockchain : Maîtriser la Conception d'Architectures
PDF
Alphorm.com Formation Sage : Gestion Commerciale
PDF
Alphorm.com Formation PHP 8 (2/6) : L'héritage en orienté objet
PDF
Alphorm.com Formation Excel 2019 : Concevoir un Tableau de Bord Interactif
PDF
Alphorm.com Formation Maya 3D : Créer un Design d'intérieur au Style Isométrique
PDF
Alphorm.com Formation VMware vSphere 7 : La Mise à Niveau
PDF
Alphorm.com Formation Apprendre les bonnes pratiques de CSS avec BEM : OOCSS ...
PDF
Alphorm.com Formation Unity : Monétiser votre jeu 3D sur les plateformes Mobiles
PDF
Alphorm.com Formation PHP 8 : Les bases de la POO
PDF
Alphorm.com Formation Power BI : Transformation de Données avec DAX et Power ...
PDF
Alphorm.com Formation Techniques de Blue Teaming : L'Essentiel pour l'Analyst...
PDF
Alphorm.com Formation Améliorer le développement avec CSS-in-JS _ Styled Comp...
PDF
Alphorm.com Formation Unity (6/7) : Maitriser l'Intelligence Artificielle de ...
PDF
Alphorm.com Formation Architecture Microservices : Jenkins et SpringBoot
PDF
Alphorm.com Formation Active Directory 2022 : Multi Sites et Services
PDF
Alphorm.com Formation Vue JS 3 : Exploiter la Composition API
Alphorm.com Formation Microsoft 365 (MS-500) : Administrateur Sécurité - Prot...
Alphorm.com Formation Google Sheets : Créer un Tableau de Bord Collaboratif a...
Alphorm.com Formation CCNP ENCOR 350-401 (6of8) : Sécurité
Alphorm.com Formation Vue JS 3 : Créer une application de A à Z
Alphorm.com Formation Blockchain : Maîtriser la Conception d'Architectures
Alphorm.com Formation Sage : Gestion Commerciale
Alphorm.com Formation PHP 8 (2/6) : L'héritage en orienté objet
Alphorm.com Formation Excel 2019 : Concevoir un Tableau de Bord Interactif
Alphorm.com Formation Maya 3D : Créer un Design d'intérieur au Style Isométrique
Alphorm.com Formation VMware vSphere 7 : La Mise à Niveau
Alphorm.com Formation Apprendre les bonnes pratiques de CSS avec BEM : OOCSS ...
Alphorm.com Formation Unity : Monétiser votre jeu 3D sur les plateformes Mobiles
Alphorm.com Formation PHP 8 : Les bases de la POO
Alphorm.com Formation Power BI : Transformation de Données avec DAX et Power ...
Alphorm.com Formation Techniques de Blue Teaming : L'Essentiel pour l'Analyst...
Alphorm.com Formation Améliorer le développement avec CSS-in-JS _ Styled Comp...
Alphorm.com Formation Unity (6/7) : Maitriser l'Intelligence Artificielle de ...
Alphorm.com Formation Architecture Microservices : Jenkins et SpringBoot
Alphorm.com Formation Active Directory 2022 : Multi Sites et Services
Alphorm.com Formation Vue JS 3 : Exploiter la Composition API

Alphorm.com Support de la Formation JavaScript , avancé

  • 1. 09/06/2016 Formation JavaScript avancé alphorm.com™© Site : http://www.alphorm.com Blog : http://blog.alphorm.com avancé JavaScript, Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 2. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Présentation du formateur • Les autres formations sur Alphorm • Le plan de formation • Présentation des outils • Les publics concernés
  • 3. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Présentation du formateur • Les autres formations sur Alphorm • Le plan de formation • Présentation des outils • Les publics concernés
  • 4. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les autres formations sur Alphorm
  • 5. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 6. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le plan de formation • Présentation de la formation • Utilisation avancée des Fonctions • Programmation Orienté Objet en JavaScript • Programmation asynchrones • Les tasks runner • Programmation Modulaire • Le futur de JavaScript
  • 7. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le plan de formation • Présentation de la formation • Utilisation avancée des Fonctions • Programmation Orienté Objet en JavaScript • Programmation asynchrones • Les tasks runner • Programmation Modulaire • Le futur de JavaScript
  • 8. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation des outils Les éditeurs • SublimeText • Atom • Microsoft Visual Studio Code • NotePad++ • jsfiddle.net Les navigateurs • Chrome • Firefox • Internet Explorer
  • 9. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les publics concernés • Les développeurs et chefs de projets qui souhaitent approfondir leurs connaissances de JavaScript.
  • 10. 09/06/2016 Formation JavaScript avancé alphorm.com™© JavaScript Avancé C’est parti !
  • 11. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les différents types de fonction Site : http://www.alphorm.com Blog : http://blog.alphorm.com Utilisation avancée des Fonctions Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 12. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Rappel sur les fonctions • Les fonctions anonymes • Les fonctions callbacks • Les fonctions immédiates • Les fonctions internes • Les scopes • Les closures
  • 13. 09/06/2016 Formation JavaScript avancé alphorm.com™© Rappel sur les fonctions • Les fonctions permettent de factoriser du code pour permettre une réutilisation
  • 14. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions anonymes • Une fonction anonyme est une fonction qui n’a pas de nom • Très peu utilisée de cette façon, on préfère :
  • 15. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions callbacks • Les fonctions sont typées comme des variables • On peut donc les passer en paramètre
  • 16. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions immédiates (Self-invoking) • Les fonctions immédiates sont une application des fonctions anonymes, mais appelées directement après leurs créations
  • 17. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions internes (Inner) • Les fonctions sont typées comme des variables • On peut donc les déclarer dans une fonction comme de simples variables
  • 18. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les scopes http://www.basing.com/books/javascript/how-variable-scope-works-in-javascript/2
  • 19. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les closures http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/what-is-closure-in-javascript/
  • 20. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Rappel sur les fonctions • Les principales structures de fonctions • Rapide présentation des scopes et closures
  • 21. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions anonymes Site : http://www.alphorm.com Blog : http://blog.alphorm.com Utilisation avancée des Fonctions Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 22. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Les fonctions anonymes • Exemple • Mise en situation
  • 23. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions anonymes • Structure fondamentale • Elles permettent d’isoler des variables dans un contexte local • Elles permettent de simuler un namespace ou packages
  • 24. 09/06/2016 Formation JavaScript avancé alphorm.com™© Examples • Déclaration de base : • Mais peu pratique alors on stocke dans une variable :
  • 25. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation • Première approche pour la réalisation d’un namespace ou package
  • 26. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation du formateur Frédéric GAURAT Développeur et formateur indépendant • Compétences Web Front : HTML5/CSS3, JavaScript, Angular Web Back : PHP, Symfony, CakePHP, JEE Mobile : Android, Cordova/PhoneGap/Ionic • Mes références Site : www.eolem.com Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
  • 27. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation du formateur Frédéric GAURAT Développeur et formateur indépendant • Compétences Web Front : HTML5/CSS3, JavaScript, Angular Web Back : PHP, Symfony, CakePHP, JEE Mobile : Android, Cordova/PhoneGap/Ionic • Mes références Site : www.eolem.com Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
  • 28. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation du formateur Frédéric GAURAT Développeur et formateur indépendant • Compétences Web Front : HTML5/CSS3, JavaScript, Angular Web Back : PHP, Symfony, CakePHP, JEE Mobile : Android, Cordova/PhoneGap/Ionic • Mes références Site : www.eolem.com Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
  • 29. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation du formateur Frédéric GAURAT Développeur et formateur indépendant • Compétences Web Front : HTML5/CSS3, JavaScript, Angular Web Back : PHP, Symfony, CakePHP, JEE Mobile : Android, Cordova/PhoneGap/Ionic • Mes références Site : www.eolem.com Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
  • 30. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation du formateur Frédéric GAURAT Développeur et formateur indépendant • Compétences Web Front : HTML5/CSS3, JavaScript, Angular Web Back : PHP, Symfony, CakePHP, JEE Mobile : Android, Cordova/PhoneGap/Ionic • Mes références Site : www.eolem.com Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat
  • 31. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation • CallBack et contexte d’exécution Mauvaise méthode Bonne méthode
  • 32. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Les fonctions callbacks • Un exemple simple d’utilisation • Mise en situation pratique qui intègre une fonction anonyme
  • 33. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions immédiates Site : http://www.alphorm.com Blog : http://blog.alphorm.com Utilisation avancée des Fonctions Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 34. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Les fonctions immédiates • Exemple • Mise en situation
  • 35. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions immédiates (Self-invoking) • Autre cas d’utilisation des fonctions anonymes • Permet la limitation de la portée des variables tout en exécutant du code
  • 36. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Fonction anonyme normale : • Fonction anonyme auto-appelée :
  • 37. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation • Fonction immédiate avec passage de paramètre
  • 38. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Les fonctions immédiates • Exemple simple • Mise en situation d’une fonction immédiate avec passage de paramètre
  • 39. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions internes Site : http://www.alphorm.com Blog : http://blog.alphorm.com Utilisation avancée des Fonctions Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 40. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Les fonctions internes • Exemple • Mise en situation
  • 41. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les fonctions internes (Inner) • Les fonctions sont des variables typées donc stockables dans une fonction ! • Elle peuvent servir pour déclarer des fonctions privées
  • 42. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Dans cet exemple MultPar2 n’est pas accessible.
  • 43. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation • Cas d’une fonction interne renvoyée par un return
  • 44. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Les fonctions internes • Un exemple simple • Cas d’un retour de fonction
  • 45. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les Scopes Site : http://www.alphorm.com Blog : http://blog.alphorm.com Utilisation avancée des Fonctions Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 46. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Les scopes • Exemple • Mise en situation
  • 47. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les scopes • En JavaScript, les portées sont définies par des fonctions et seulement par des fonctions • Le « hoisting » vous assure qu’une variable déclarée tard dans le code sera remontée dans sa portée.
  • 48. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Différences de portée de variable
  • 49. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation • Le hoisting • Dans ce cas ‘var b’ est remonté • La syntaxe use-strict impose une rigueur de codage (utilisation de ‘var’ obligatoire par exemple)
  • 50. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation (suite) • Le hoisting • Dans ce cas ‘var b’ est remonté mais pas b=2, le résultat est NaN
  • 51. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation (suite) • Le hoisting pour les fonctions • Pas d’erreurs dans Chrome, en revanche ça ne fonctionne pas dans Firefox
  • 52. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Les scopes, le hoisting • Exemple • Mise en situation du hoisting sur variables et fonctions
  • 53. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les closures Site : http://www.alphorm.com Blog : http://blog.alphorm.com Utilisation avancée des Fonctions Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 54. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Les closures • Exemple • Mise en situation
  • 55. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les closures • La notion de closure est associée à la notion de portée de variable • Une variable est « enfermée » dans sa fonction ( sa portée) • Une fonction définie dans la même fonction (portée) va se « souvenir » de cette variable https://developer.mozilla.org/fr/docs/Web/JavaScript/Closures
  • 56. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les closures • afficheNom() va se souvenir de la variable ‘nom’ déclarée dans la portée.
  • 57. 09/06/2016 Formation JavaScript avancé alphorm.com™© Mise en situation • Ici, on stocke un tableau contenant le nom des jours. • Dans ce cas le tableau n’est créé qu’une seule fois, pas de multiplication de ce tableau en mémoire
  • 58. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les autres formations sur Alphorm
  • 59. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les autres formations sur Alphorm
  • 60. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les autres formations sur Alphorm
  • 61. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les autres formations sur Alphorm
  • 62. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les autres formations sur Alphorm
  • 63. 09/06/2016 Formation JavaScript avancé alphorm.com™© Des tableaux aux objets (suite) • JavaScript ne supporte pas les tableaux associatifs • Pour implémenter un tableau associatif, on passe par un objet :
  • 64. 09/06/2016 Formation JavaScript avancé alphorm.com™© Accès aux propriétés • On utilise la notation « pointée »
  • 65. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Rappel sur les objets en JavaScript • Comparaison des syntaxes des tableaux et des objets • L’accès aux propriétés
  • 66. 09/06/2016 Formation JavaScript avancé alphorm.com™© Rappel sur les prototypes Site : http://www.alphorm.com Blog : http://blog.alphorm.com POO en JavaScript Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 67. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Présentation de la notion de prototype •Exemples
  • 68. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de la notion de prototype • En JavaScript, chaque objet à un prototype • Le prototype est une propriété de cet objet • Le prototype lui-même est un objet • Tous les objets JavaScript héritent leurs méthodes de leurs prototypes
  • 69. 09/06/2016 Formation JavaScript avancé alphorm.com™© Notation litéral • La propriété __proto__ donne un accès au prototype de l’objet
  • 70. 09/06/2016 Formation JavaScript avancé alphorm.com™© Notation avec constructeur • Peu importe la façon de créer l’objet (littéral ou avec constructeur)
  • 71. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ajout de propriétés et de méthodes • JavaScript est dynamique, on peut ajouter des méthodes après déclaration et instanciation de l’objet.
  • 72. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ajout de propriétés et de méthodes (suite) • En ajoutant propriétés et méthodes sur le prototype c’est l’ensemble des objets qui en bénéficient
  • 73. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Présentation de la notion de prototype • Ajout de propriétés et méthodes sur un objet • Ajout de propriétés et méthodes sur le prototype d’un objet
  • 74. 09/06/2016 Formation JavaScript avancé alphorm.com™© Implémentation des constructeurs Site : http://www.alphorm.com Blog : http://blog.alphorm.com POO en JavaScript Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 75. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Présentation des fonctions comme constructeur d’objet • La propriété constructor • Exemples
  • 76. 09/06/2016 Formation JavaScript avancé alphorm.com™© Fonctions comme constructeur d’objet • JavaScript n’a pas de notion de classe. • Pour construire un objet on passe par une fonction constructeur • Le constructeur est appelé au moment de l’instanciation et toutes les opérations qui y sont déclarées sont exécutées
  • 77. 09/06/2016 Formation JavaScript avancé alphorm.com™© La propriété constructor • La propriété constructor renvoie la référence à la fonction utilisée pour créer le prototype de l’instance
  • 78. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Utilisation d’un constructeur
  • 79. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Affichage de la fonction utilisée pour construire l’objet
  • 80. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Modifier un constructeur en utilisant la propriété constructor • En réalité on ne change pas le constructeur mais seulement ce que renvoie la propriété constructor (il ne faut pas se fier à ce que renvoie constructor)
  • 81. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • L’utilisation des fonctions constructeurs • La propriété constructor
  • 82. 09/06/2016 Formation JavaScript avancé alphorm.com™© Implémentation de l’encapsulation Site : http://www.alphorm.com Blog : http://blog.alphorm.com POO en JavaScript Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 83. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Encapsuler des propriétés et méthodes • Simuler les propriétés et méthodes publics • Simuler les propriétés et méthodes privates
  • 84. 09/06/2016 Formation JavaScript avancé alphorm.com™© Encapsuler des propriétés et méthodes • JavaScript ne dispose pas de moyens pour déclarer des propriétés ou méthodes public, private ou protected • Pour simuler ce comportement nous allons exploiter le comportement normal de la déclaration de variable
  • 85. 09/06/2016 Formation JavaScript avancé alphorm.com™© Simuler les propriétés et méthodes publics • Pour déclarer des méthodes ou propriétés public ou utilise « this »
  • 86. 09/06/2016 Formation JavaScript avancé alphorm.com™© Simuler les propriétés et méthodes privates • Pour déclarer des méthodes ou propriétés privates ou utilise « var »
  • 87. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Les moyens de simuler les « privates » et « public » que l’on trouve dans d’autres langages.
  • 88. 09/06/2016 Formation JavaScript avancé alphorm.com™© L’héritage en JavaScript Site : http://www.alphorm.com Blog : http://blog.alphorm.com POO en JavaScript Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 89. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Implémenter l’héritage en JavaScript •Exemples
  • 90. 09/06/2016 Formation JavaScript avancé alphorm.com™© Implémenter l’héritage en JavaScript • L’héritage permet de créer des objets spécialisés à partir d’un autre objet. JavaScript s’appuie sur l’héritage unique. • Pour implémenter l’héritage, on assigne une instance de l’objet parent à la propriété prototype de l’objet fils. • On parle donc d’héritage de prototype et de « prototype chain » • Pour éviter que le constructeur soit celui du parent on réassigne le constructeur à l’enfant.
  • 91. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple d’héritage obj1 obj2
  • 92. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple d’héritage
  • 93. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •La notion d’héritage de prototype en JavaScript
  • 94. 09/06/2016 Formation JavaScript avancé alphorm.com™© Utilisation du « this » Site : http://www.alphorm.com Blog : http://blog.alphorm.com POO en JavaScript Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 95. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Définition et utilisation de « this » •Exemples
  • 96. 09/06/2016 Formation JavaScript avancé alphorm.com™© Définition et utilisation de « this » • Le « this » est une référence à un objet (une fonction en JavaScript) • La valeur de this est déterminée par la façon dont on appelle la fonction. • Dans le contexte global : this fait référence à l’objet global
  • 97. 09/06/2016 Formation JavaScript avancé alphorm.com™© Dans un contexte de fonction • En mode non strict, this n’étant pas défini il prend l’objet global • En mode strict, this n’étant pas défini il la valeur undefined
  • 98. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 99. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 100. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 101. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 102. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 103. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 104. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, Avancé DART Tests Unitaires JavaScript, les fondamentaux CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 105. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •La définition d’un callback hell
  • 106. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les Promesses Site : http://www.alphorm.com Blog : http://blog.alphorm.com Programmation asynchrones Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 107. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Définition d’une promesse •Exemples
  • 108. 09/06/2016 Formation JavaScript avancé alphorm.com™© Définition d’une promesse • Une promesse est utilisée pour réaliser des opérations asynchrone. • Elle peut être dans un de ces états : en attente : état initial, la promesse n'est ni remplie, ni rompue tenue : l'opération a réussi rompue : l'opération a échoué acquittée : la promesse est tenue ou rompue mais elle n'est plus en attente. https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise
  • 109. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Nous souhaitons faire la somme de 2 entiers. • Ces entiers seront calculés plus tard (on simule une requête serveur)
  • 110. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple du callback hell • Pour synchroniser les traitements nous exécuterons les traitements l’un après l’autre.
  • 111. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple avec des promesses • Etape 1 : on créée un objet Promise • Etape 2 : on attend que la promesse soit tenue (resolve) avec la méthode then
  • 112. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple avec des promesses • Pour synchroniser les 2 traitements : Lorsqu’une promesse est résolue on enchaîne avec l’autre
  • 113. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple avec des promesses • Pour synchroniser les traitements on peut passer par la méthode all() qui reçoit un tableau de promesses et qui sera résolue lorsque toutes les promesses du tableau le seront.
  • 114. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • Le fonctionnement et l’utilisation des promesses • Un exemple d’utilisation
  • 115. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation et tâches de base Les tasks runner Site : http://www.alphorm.com Blog : http://blog.alphorm.com Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 116. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Les besoins des développeurs JavaScript •Les outils
  • 117. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les besoins des développeurs JavaScript JavaScript Qualité du code Minification Production CSS Préprocesseur LESS/Sass
  • 118. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les outils • Exécuteurs de tâches
  • 119. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •L’intérêts d’utiliser des exécuteurs de tâches •Les principaux outils
  • 120. 09/06/2016 Formation JavaScript avancé alphorm.com™© GruntJS Les tasks runner Site : http://www.alphorm.com Blog : http://blog.alphorm.com Frédéric GAURAT Développeur et Formateur Consultant indépendant
  • 121. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Présentation de GruntJS •Utilisation
  • 122. 09/06/2016 Formation JavaScript avancé alphorm.com™© GruntJS • GruntJS est un exécuteur de tâches • Il s’appuie sur des plugins • Ainsi que sur un fichier (GruntFile) pour configurer les plugins
  • 123. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le plan de formation • Présentation de la formation • Utilisation avancée des Fonctions • Programmation Orienté Objet en JavaScript • Programmation asynchrones • Les tasks runner • Programmation Modulaire • Le futur de JavaScript
  • 124. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le plan de formation • Présentation de la formation • Utilisation avancée des Fonctions • Programmation Orienté Objet en JavaScript • Programmation asynchrones • Les tasks runner • Programmation Modulaire • Le futur de JavaScript
  • 125. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le fichier Gruntfile.js • Structure de base
  • 126. 09/06/2016 Formation JavaScript avancé alphorm.com™© Configuration d’un plugin • Chargement du plugin • Enregistrement de la tâche
  • 127. 09/06/2016 Formation JavaScript avancé alphorm.com™© Configuration d’un plugin (suite)
  • 128. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert • L’exécuteur de tâche GruntJS • L’installation • L’installation et la configuration d’un plugin
  • 129. 09/06/2016 Formation JavaScript avancé alphorm.com™© Frédéric GAURAT Formateur et Consultant indépendant Ingénierie statistique et financière GulpJS Les tasks runner Site : http://www.alphorm.com Blog : http://blog.alphorm.com
  • 130. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Présentation de GulpJS •Utilisation de GulpJS
  • 131. 09/06/2016 Formation JavaScript avancé alphorm.com™© GulpJS • GulpJS est un exécuteur de tâches • Il s’appuie sur des plugins • Ainsi que sur un fichier (gulpfile.js) pour configurer les plugins • Il se diffère de GruntJS dans son mode de fonctionnement : Grunt s’appuie sur des fichiers pour la réalisation des tâches GulpJS s’appuie sur des streams (des fluxs entre les tâches)
  • 132. 09/06/2016 Formation JavaScript avancé alphorm.com™© Installation •L’installation se fait avec l’utilitaire npm
  • 133. 09/06/2016 Formation JavaScript avancé alphorm.com™© Installation d’un plugin • Pour une tâche de minification le plugin est uglify http://gulpjs.com/plugins/ pour la totalité des plugins https://www.npmjs.com/package/gulp-uglify/ pour le plugin uglify • Installation du plugin
  • 134. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le plan de formation • Présentation de la formation • Utilisation avancée des Fonctions • Programmation Orienté Objet en JavaScript • Programmation asynchrones • Les tasks runner • Programmation Modulaire • Le futur de JavaScript
  • 135. 09/06/2016 Formation JavaScript avancé alphorm.com™© Configuration d’un plugin • Installation du plugin • Chargement du plugin • Enregistrement de la tâche
  • 136. 09/06/2016 Formation JavaScript avancé alphorm.com™© Configuration d’un plugin (suite)
  • 137. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •L’exécuteur de tâche GulpJS •L’installation •L’installation et la configuration d’un plugin
  • 138. 09/06/2016 Formation JavaScript avancé alphorm.com™© Frédéric GAURAT Formateur et Consultant indépendant Ingénierie statistique et financière Organiser son code et le rendre performant Programmation modulaire Site : http://www.alphorm.com Blog : http://blog.alphorm.com
  • 139. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan • Introduction à la programmation modulaire • Rappel sur le pattern Module • Les problèmes et les solutions
  • 140. 09/06/2016 Formation JavaScript avancé alphorm.com™© La programmation modulaire • En JavaScript il n’y a pas d’instruction pour créer des modules • Il faut utiliser le pattern module • Il n’y a pas de gestion de dépendance • L’ensemble des scripts doivent être chargés au démarrage
  • 141. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le pattern module • Le pattern module permet d’encapsuler du code comme un package ou namespace • Il s’appuie sur une « Anonymous Closure » Permet la déclaration de variable privée Permet de maintenir l’état des variables
  • 142. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le pattern module (suite) • Anonymous Closure • Ajout d’une dépendance
  • 143. 09/06/2016 Formation JavaScript avancé alphorm.com™© Le pattern module (suite) • Module export
  • 144. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les problèmes • Les modules sont des unités de code indépendant les uns des autres • Ils sont stockés dans des fichiers distincts • Difficile de gérer les dépendances • Difficile de charger les fichiers au bon moment
  • 145. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les solutions • Asynchronous module definition (AMD) Spécification JavaScript Définit une API pour décrire des modules, gérer leurs dépendances et les charger dynamiquement (éventuellement)
  • 146. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •La programmation modulaire •Le pattern module •La spécification AMD
  • 147. 09/06/2016 Formation JavaScript avancé alphorm.com™© Frédéric GAURAT Formateur et Consultant indépendant Ingénierie statistique et financière Utilisation de RequireJS Programmation Modulaire Site : http://www.alphorm.com Blog : http://blog.alphorm.com
  • 148. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Présentation de RequireJS •Utilisation de RequireJS
  • 149. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de RequireJS •RequireJS est un outil permettant le chargement de fichiers et de modules JavaScript •http://requirejs.org/
  • 150. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation des outils Les éditeurs • SublimeText • Atom • Microsoft Visual Studio Code • NotePad++ • jsfiddle.net Les navigateurs • Chrome • Firefox • Internet Explorer
  • 151. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation des outils Les éditeurs • SublimeText • Atom • Microsoft Visual Studio Code • NotePad++ • jsfiddle.net Les navigateurs • Chrome • Firefox • Internet Explorer
  • 152. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation des outils Les éditeurs • SublimeText • Atom • Microsoft Visual Studio Code • NotePad++ • jsfiddle.net Les navigateurs • Chrome • Firefox • Internet Explorer
  • 153. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation des outils Les éditeurs • SublimeText • Atom • Microsoft Visual Studio Code • NotePad++ • jsfiddle.net Les navigateurs • Chrome • Firefox • Internet Explorer
  • 154. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation des outils Les éditeurs • SublimeText • Atom • Microsoft Visual Studio Code • NotePad++ • jsfiddle.net Les navigateurs • Chrome • Firefox • Internet Explorer
  • 155. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation des outils Les éditeurs • SublimeText • Atom • Microsoft Visual Studio Code • NotePad++ • jsfiddle.net Les navigateurs • Chrome • Firefox • Internet Explorer
  • 156. 09/06/2016 Formation JavaScript avancé alphorm.com™© Installation • Le compilateur s’installe via npm : • Il est possible de tester directement en ligne sur le site : http://coffeescript.org/ (‘Try Coffeescript’)
  • 157. 09/06/2016 Formation JavaScript avancé alphorm.com™© Utilisation • Appel de fonction • Déclaration de fonction
  • 158. 09/06/2016 Formation JavaScript avancé alphorm.com™© Utilisation • Déclaration de fonction (suite) • Déclaration de variable et portée lexicale
  • 159. 09/06/2016 Formation JavaScript avancé alphorm.com™© Utilisation • Les boucles
  • 160. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •Une introduction à CoffeeScript •Quelques exemples d’utilisation
  • 161. 09/06/2016 Formation JavaScript avancé alphorm.com™© Frédéric GAURAT Formateur et Consultant indépendant Ingénierie statistique et financière Dart Le Futur de JavaScript Site : http://www.alphorm.com Blog : http://blog.alphorm.com
  • 162. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Présentation de Dart •Utilisation
  • 163. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de Dart • Langage de développement web (objet) proposé par Google • Il a vocation à remplacer le JavaScript • Pour le moment il permet d’obtenir du JavaScript après compilation • Il peut tourner dans une VM côté serveur • Il est testable en ligne : https://dartpad.dartlang.org • Contrairement aux autres outils, il ne s’installe pas avec npm • https://www.dartlang.org/downloads/
  • 164. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple • Exemple HelloWorld
  • 165. 09/06/2016 Formation JavaScript avancé alphorm.com™© Déclaration de variable • Il est possible d’annoter les variables avec un type
  • 166. 09/06/2016 Formation JavaScript avancé alphorm.com™© Déclaration de fonction • Les type s’appliquent aussi aux fonctions et les déclarations sont soumises au compilateur
  • 167. 09/06/2016 Formation JavaScript avancé alphorm.com™© Les publics concernés • Les développeurs et chefs de projets qui souhaitent approfondir leurs connaissances de JavaScript.
  • 168. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •Une introduction à Dart •Quelques exemples d’utilisation
  • 169. 09/06/2016 Formation JavaScript avancé alphorm.com™© Frédéric GAURAT Formateur et Consultant indépendant Ingénierie statistique et financière TypeScript Le Futur de JavaScript Site : http://www.alphorm.com Blog : http://blog.alphorm.com
  • 170. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Présentation de TypeScript •Exemples d’utilisation
  • 171. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de TypeScript • TypeScript est un langage développé par Microsoft • Il a pour but d’améliorer la production de code JavaScript • Il intègre JavaScript (JavaScript est utilisable dans TypeScript) • Il a été utilisé pour le développement d’Angular 2. • Il est testable en ligne : http://www.typescriptlang.org/play/index.html
  • 172. 09/06/2016 Formation JavaScript avancé alphorm.com™© Installation et utilisation
  • 173. 09/06/2016 Formation JavaScript avancé alphorm.com™© Exemple •Les variables sont typées
  • 174. 09/06/2016 Formation JavaScript avancé alphorm.com™© Déclaration de class
  • 175. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert •Présentation de TypeScript •Quelques exemples d’utilisation
  • 176. 09/06/2016 Formation JavaScript avancé alphorm.com™© Frédéric GAURAT Formateur et Consultant indépendant Ingénierie statistique et financière ECMAScript6 Le Futur de JavaScript Site : http://www.alphorm.com Blog : http://blog.alphorm.com
  • 177. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Présentation de ECMA •Présentation de ECMAScript6 •Exemples d’utilisation
  • 178. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de ECMA • ECMA (European Computer Manufacturers Association) est une organisation de standardisation. • Elle est à l’origine des standards pour Dart (ECMA-408) • ECMAScript (ECMA-262) mis en œuvre dans : ActionScript (Adobe), JavaScript, C++ (norme 2011).
  • 179. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de ECMAScript6 • Aussi nommée ECMSScript 2015 (sortie en Juin 2015) • N’est pas encore supporté par les navigateurs du moment. • Il est possible de passer par transcompilateur (compilateur de source à source) pour transformer l’ECMAScript6 en ECMAScript5 avec http://babeljs.io/
  • 180. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de ECMAScript6 (suite) • Portée de variable avec let • Template String
  • 181. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de ECMAScript6 (suite) • Paramètre de fonction par défaut • Les Lambdas (Arrow function)
  • 182. 09/06/2016 Formation JavaScript avancé alphorm.com™© Présentation de ECMAScript6 (suite) • Les classes et héritage
  • 183. 09/06/2016 Formation JavaScript avancé alphorm.com™© JavaScript Avancé C’est parti !
  • 184. 09/06/2016 Formation JavaScript avancé alphorm.com™© JavaScript Avancé C’est parti !
  • 185. 09/06/2016 Formation JavaScript avancé alphorm.com™© Plan •Ce qui a été couvert •Ce qui reste à aborder
  • 186. 09/06/2016 Formation JavaScript avancé alphorm.com™© Ce qu’on a couvert dans cette formation • Présentation de la formation Présentation de la formation • Utilisation avancée des Fonctions Les différents types de fonction (anonymes, callback, immédiates, internes) Les scopes et les closures • Programmation Orienté Objet en JavaScript Rappel sur les objets et prototypes Implémentation des constructeurs Implémentation de l’encapsulation L’héritage en JavaScript Utilisation du « this » • Programmation asynchrones Le callback hell Les promesses • Les tasks runner Les tâches de base (Qualité,Obfuscation,…) Présentation de Grunt et Gulp • Programmation Modulaire Organiser son code et le rendre performant : Asynchronous Module Definition (AMD) Utilisation de RequireJS • Le futur de JavaScript CoffeeScript / Dart / TypeScript La spécification ECMAScript 6
  • 187. 09/06/2016 Formation JavaScript avancé alphorm.com™© Cursus formations JavaScript JavaScript, les fondamentaux DART Tests Unitaires JavaScript, Avancé CoffeeScript Tests fonctionnels TypeScript AngularJS 2, les fondamentaux AngularJS 2, Avancé
  • 188. 09/06/2016 Formation JavaScript avancé alphorm.com™© A bientôt ! Site : www.eolem.com Profil Alphorm : http://www.alphorm.com/formateur/frederic-gaurat