Skip to content

Instantly share code, notes, and snippets.

@micahlmartin
Created December 26, 2015 17:01
Show Gist options
  • Save micahlmartin/3f5f4514ea0f464ba80d to your computer and use it in GitHub Desktop.
Save micahlmartin/3f5f4514ea0f464ba80d to your computer and use it in GitHub Desktop.
Example of global variables
var updateQuestionStatus = function (student, logInfo, test, sessionId, status, confidence, timeTaken, earned, possible) {
// Question gets scoped as a global variable because there is no 'var' statment. Therefore it will never get cleaned up
// by the garbage collector.
question = test.getSession(sessionId);
logInfo.testId = test.id;
if (question) {
question.status = status;
question.confidence = confidence;
question.timeTaken = timeTaken;
question.earned = earned;
// something up with the possible values sometimes
if (possible && possible > 0) {
question.possible = possible;
} else {
question.possible = 1;
}
student.safeSave()
.then(function () {
logInfo.msg = 'update successful';
log.info(logInfo);
deferred.resolve(student);
}, function (error) {
logInfo.msg = error;
log.error(logInfo);
deferred.reject(error);
});
} else {
logInfo.msg = 'no question matching the id ' + sessionId + ' could be located';
log.info(logInfo);
deferred.reject(logInfo.msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment