What I currently have is 2 functions with callbacks.
At the end of validateEvent, there will be 2 variables isDeactivated
and eventOrganizer
.
While at the end of validateCheckIn, there will be 1 variable which is isCheckIn
.
What I want to achieve now is merging the results of the 2 functions validateEvent and validateCheckIn into 1 new function where I can interact with 3 of the variables isDeactivated
, eventOrganizer
and isCheckIn
in it.
What I've found so far is something like this: link
But what if I wanted to add extra code in the newly merged function?
var isDeactivated = false;
var eventOrganizer;
var isCheckIn = false;
function validateEvent(result) {
$.post(
"**displayEventAPI**",
{
id: eventID,
}).done(function (data) {
result(
data["eventList"][0]["event_status"],
data["eventList"][0]["event_creator"]
);
}
)
}
validateEvent(function(event_status, event_creator) {
if (event_status == 0) {
isDeactivated = true;
}
eventOrganizer = event_creator;
console.log(isDeactivated, '--isDeactivated');
console.log(eventOrganizer, '--eventOrganizer');
});
function validateCheckIn(result) {
$.post(
"**displayAttendanceAPI",
{
event_id: eventID,
}).done(function (data) {
for (var i = 0; i < data.attendanceList.length; i++) {
if (data.attendanceList[i].badge_id === badgeID) {
isCheckIn = true;
}
}
result(
isCheckIn
);
}
)
}
validateCheckIn(function(isCheckIn) {
console.log(isCheckIn, '--isCheckIn');
});