fetch
let requestObj = `images/${i}.jpg`;
fetch(requestObj).then(function(response) {
return response.blob();
}).then(function(myBlob) {
let {size,type} = myBlob,
objectURL = URL.createObjectURL(myBlob);
document.querySelector("#idImage").src = objectURL;
});
en action
Class : this how to
Nous allons tenter de corriger le code
Uncaught TypeError: Cannot read property 'somme' of undefined
Corrections
ajouter(tableau) {
tableau.forEach(function(element) {
this.somme += element;
++this.compte;
}, this); // passage de this à forEach
}
ajouter(tableau) {
tableau.forEach((element) => {
this.somme += element;
++this.compte;
});
}
code à corriger !
Uncaught TypeError: Cannot read property 'somme' of undefined
Corrections
binding
ajouter(tableau) {
tableau.forEach(function(element) {
this.somme += element;
++this.compte;
}, this); // passage de this à forEach
}
arrow function
ajouter(tableau) {
tableau.forEach((element) => {
this.somme += element;
++this.compte;
});
}
Inscription à :
Articles (Atom)