Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am currently refactoring an application that i built in JavaScript. The applic

ID: 646968 • Letter: I

Question

I am currently refactoring an application that i built in JavaScript.
The application uses a starting hour and a total working hour count in order to construct a timetable for daily, weekly and monthly views. The starting hour and total working hour count are the same for all timetables

I considered using a pattern to initialise the Timetable and started reading up on how to proceed in doing so in Javascript as I am not too familiar with the language. My orginal initialisation function for the Timetable had the following signature:

FillTimeTable( startingTimeWeekDay, workinghourCountWeekDay );
Problem with this method is that for a different view of the timetable I have to call the other views with the same signature again.

FillWeeklyTimeTable( startingTimeWeekDay, workinghourCountWeekDay );
FillMonthlyTimeTable( startingTimeWeekDay, workinghourCountWeekDay );
If the working hours change I or the poor bugger maintaining my code would have to alter them at different locations within the code and due to the way I organised my code they are not placed as neatly as here. So during refactoring I considered alternatives like a global variable, Singleton or an Object.

I read about objects, private members and constructors and decided that this might be the solution after reading up on Singleton Implementations and binning the global variables.

So currently I have the following code:

function Timetable( startingTimeWeekDay, workinghourCountWeekday) {
    this.startWeekday = startingTimeWeekDay;
    this.hoursWeekday = workinghourCountWeekday;
}

Timetable.prototype.startWeekday = function() {
    return this.startWeekday;
}

Timetable.prototype.hoursWeekday = function() {
    return this.hoursWeekday;
}

var myTimetable = new Timetable( 6, 8 );
Everything is working fine so far, but myTimetable just seems like a really fancy way of declaring a global variable to me.

Is this the case?

Did I just decide on the wrong strategy or is this the way to go or have I missed something essential to working with JavaScript?

Explanation / Answer

If the application