Voila je suis actuellement en train de faire un petit projet ou je crée dynamiquement des cocktails et tout ça

J'ai actuellement mes 2 classes ingrédients et ingrédient:
Code : Tout sélectionner
export class Ingredients {
constructor () {
this.ingredients = []; // list of instances of "Ingredient"
}
add(ingredient) {
this.ingredients.push(new Ingredient(ingredient));
}
get_ingredient() {
for(let i = 0; i <= this.ingredients.length; ++i)
{
return this.ingredients[i].get();
}
}
}
export class Ingredient {
constructor(ingredient) {
this.ingredient = ingredient;
}
get()
{
return this.ingredient;
}
}
Voila l'appel Ajax :
dans data.ingredient j'ai le nom de l'ingredient
Code : Tout sélectionner
let AjaxIngredient = ($self,liste_ingredient) => {
let $data = $self.serialize();
$self.hide();
$.ajax({
url: $self.attr("action"),
method: $self.attr("method"),
data: $data,
dataType: "json",
})
.done(function (data) {
if (data.hasOwnProperty("result")) {
if (data.result) {
//recuperer data.ingredient
liste_ingredient.add(data.ingredient);
console.log(liste_ingredient.get_ingredient());
$("#message_formulaire").empty().append("<p style='color: green'>"+data.message+"</p>").fadeIn(1000);
}else {
$self.fadeIn(2000);
if (data.hasOwnProperty("message")) {
/* display message */
$("#message_formulaire").empty().append("<p style='color: red' >"+data.message+"</p>").fadeIn(1000);
}
}
}
})
.fail(function () {});
return false;
}

Connexion
liste_ingredient = new Ingredients();
Appel fonction1(liste_ingredient);
fonction1(
appel fonction2(liste_ingredient)
);
fonction2(
appel fonction3.....
jusqu'à l'appel Ajax vu que c'est que des fonctions imbriquées.
Bon voila j'ai fait un beau pavé xD J'espère surtout avoir été clair

Merci beaucoup a tout ceux qui prendront le temps de me répondre <3