Last active
May 21, 2018 18:05
-
-
Save lelbil/4ade487c1339c4435f2cda3268be8cf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 | |
const val2 = 2 | |
//2 | |
// Non, on ne peut pas modifer la valeur d'une constante | |
//3 | |
// Dans le cas où on veut définir une variable (on voudra pouvoir changer la valeur après) | |
//4 | |
// let pour définir des variables, const pour des constantes | |
//5 | |
const multiplierPar2 = arg1 => arg1 * 2 | |
//multiplierPar2(70) | |
//6 | |
// Non, return n'est pas obligatoire | |
//7 | |
const multi2 = (arg1 = 10) => arg1 * 2 | |
//multi2(14) | |
//multi2() | |
//8 | |
// les params Rest nous permettent de définir un nombre variable et infini d'arguments dans la signature d'une fonction qu'on réccupère en forme de Array | |
// Le spread operator nous permet d'étaler un array, en partant du nom de la variable de l'array pour se retrouver avec ses éléments | |
//9 | |
illimite = (arg1, arg2, ...leReste) => [arg1, arg2, ...leReste].reduce((acc, arg) => acc += arg, 0) | |
//illimite(1, 2, 3, 4) | |
//10 | |
const tableau = [1, 2, 3, 4] | |
//illimite(...tableau) | |
//11 | |
// ça permet d'utiliser moins de variables, avoir un handle pour un nombre indéfini de variables, passer les valeurs d'un tableau sans les initier.. etc | |
//12 | |
const h = 'hello' | |
const w = 'world' | |
//console.log(`${h} ${w}`) | |
//13 | |
const b = 'Billel' | |
const a = 'ATTOUCHI' | |
//console.log(`${b} ${a}`) | |
//14 | |
// avec le signe '+' comme ci: console.log(h + " " + w); par exemple | |
//15 | |
const teamName = "tooling" | |
const people = [{ name: "Jennie", role: "senior" }, | |
{ name: "Ronald", role: "junior" }, | |
{ name: "Martin", role: "senior" }, | |
{ name: "Anneli", role: "junior" }] | |
//on peut avoir un seul template aussi | |
let message = `There are ${people.length} people on the ${teamName} team.\n` + | |
`Their names are ${people.map(person => person.name)}.\n` + | |
`${people.filter(person => person.role === "senior").length} of them have a senior role.` | |
//console.log(message) | |
//16 | |
const a0 = "hello world" | |
const obj01 = { a0 } | |
//console.log(obj01.a0) | |
//17 | |
const b0 = [1, 2, 3] | |
const obj02 = { b0 } | |
//console.log(obj02.b0) | |
//18 | |
const obj03 = { obj01, obj02 } | |
//console.log(obj03) | |
//19 et 20 | |
const a = "hello world" | |
const objComputed = { | |
[a]: 'test', | |
maFunction() { | |
console.log('maFunction a été appelé') | |
} | |
} | |
//21 | |
var ids = { | |
next: 0, | |
get() { | |
console.log(this.next++) | |
} | |
} | |
//22 | |
var list = [1, 2, 3] | |
const [a2, b] = list | |
//23 | |
var film = { nom: "Forrest Gump", annee: 1994, duree: "2h20min", realisateur: "Robert Zemeckis", like: 100806 } | |
const { nom, annee } = film | |
//24 | |
const { like } = film | |
//console.log('Like', like) | |
//25 | |
// La fonction reçoit en argument un objet dans lequel on s'attend à avoir deux propriétés name et val. On utilise le destructuring pour récupérer les valeurs de ces deux propriétés dans les variables name et val utilisables dans la fonction. | |
//26 | |
const maFunction = ({a}) => {console.log('A', a)} | |
//maFunction({ a: 1, b: 1}) | |
//27 | |
const maFunction2 = ({a, b}) => {console.log(a + b)} | |
//maFunction2({ a: 1, b: 1}); | |
//29 | |
class multi { | |
constructor (a, b) { | |
this.a = a | |
this.b = b | |
} | |
affiche () { | |
const result = this.a * this.b | |
console.log(result) | |
return result | |
} | |
} | |
const test = new multi(4, 3) | |
//test.affiche() | |
//30 | |
class Point{ | |
constructor(x, y) { | |
this.x = x | |
this.y = y | |
} | |
plus(point) { | |
return new Point(this.x + point.x, this.y + point.y) | |
} | |
} | |
//console.log(new Point(1,2).plus(new Point(2, 1))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment