I have a problem when it comes to create an object in javascript inside a promise chain. For some reason it gets all messed up and my attributtes are not showing correctly:
var historyManager = new HistoryManager();
var examManager = new ExamManager();
var recipeManager = new RecipeManager();
var historiaObj = {
obs : "",
freR : "",
exams : [],
meds : [],
content : ""
};
var allHistory = Object.create(historiaObj);
return historyManager.refresh(history).then(function (historyRefreshed) {
history = historyRefreshed;
allHistory.obs = historyRefreshed.get("obs");
return examManager.getByHistory(historyRefreshed);
}).then(function (examenFisico) {
allHistory.freR = examenFisico.get("freR");
return recipeManager.getByHistory(history)
}).then(function (recipe) {
allHistory.content = recipe.get("content");
return recipeManager.getMedsByRecipe(recipe);
}).then(function (meds) {
for(var i = 0 ; i < meds.length ; i++){
allHistory.meds.push(meds[i].get("name"))
}
}).then(function () {
return allHistory;
});
For some reason when I try to check if the meds where added correctly, they are under _proto_
but not in the main object. How can I fix this, or what is it that I'm doing wrong.
Thanks in advance.