As a novice coder, I am currently trying to decipher a piece of sample code from a Q&A application.
In the server-side code snippet, the Question
object contains a property known as answers
:
var Question = new Schema({
title: {type:String, required: true, trim:true},
answers: [Answer],
});
Interestingly, although answers
is only defined within the Question
object, it is also referenced alongside var question
in the subsequent for
loop:
var question;
var answerController = Alloy.createController('answer');
exports.setQuestion = function(c, q){
question = c.get('questions')[q];
for(var i = 0; i < question['answers'].length; i++){
var answer = question['answers'][i],
This raises the question: if answers
was initially declared within the context of the Question
object, how is it being utilized with question
here?