I'm building a simple quiz app and wanted to make it more scalable by putting my code into an object. The parameters list looks a bit messy to me. Is this a normal way to use an object or is there a better way?
Thanks
// above here I have a JSON object with questions:
var quiz = new question($('#quiz-container'), $('.alert'), 0, [], questions[0].level[0]);
// for debugging
console.log(quiz);
function question(quizContainer, alert, questionCounter, selection, level) {
this.quizContainer = quizContainer;
this.alert = alert;
this.questionCounter = questionCounter;
this.selection = selection;
this.level = level;
function createQuestion(index) {
//TODO
}
}
createQuestion
should be the single point to create an object (and should not be possible to callnew Question()
). The number of arguments passed to the constructor can be reduced too (#quiz-container
is a global unique object, probably.alert
is unique too), other default values such as 0 or [] can be set inside the constructor (no need to pass them as arguments). \$\endgroup\$