JS - Chapitre 02 - Objet immutable Flashcards

1
Q

on considère les objets comme?

A

des structures de données, sans comportement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

objet

A

collection de propriétés

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

immutable avec const?

A

const fruit = { name: ‘apple’; }
fruit.name = ‘orange’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

freezing

A

const fruit = Object.freeze({name: ‘apple’});

impossible de changer name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

defaut de freezing

A

seulement a shallow copy. objet contenant des objets mutables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

deep freeze

A

copie profonde

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

rendre immutable en JS

A

lint (interdiction)
const, copie shallow, copie profonde

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

linting

A

utiliser es-lint pour donner des directives

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Changer la valeur d’un immutable

A

const product = {
name: ‘apple’,
quantity : 1
}

changement

const newProduct = {
…product,
quantity: 2
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Ajouter une propriété à un immutable

A

const product = {
name: ‘apple’,
quantity : 1
}

changement

const newProduct = {
…product,
type: ‘fruit’
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly