\chapter{Class Based Javascript Websites} \ChapterLabel{ClassBasedJSRefactor} \section{Overview} The Color Buttons website was redesigned to use a class-based JavaScript implementation. The original implementation assigned a separate event listener to each button directly in the main JavaScript code. Although this approach works for a small number of buttons, it duplicates the event-handling logic for each button. The updated design introduces a \texttt{ColorButton} class. Each button on the webpage is represented by an instance of this class. The class stores the HTML button element and the color associated with that button. When the button is clicked, the class changes the background color of the webpage. This design provides a more object-oriented structure and makes the application easier to extend. For example, additional colors can be added by creating additional instances of the \texttt{ColorButton} class without duplicating the event-handling implementation. \section{UML Class Diagram} \begin{figure}[htbp] \centering \includegraphics{HW2 images/UML-JS.png} \caption{UML class diagram for the class-based Color Buttons application} \label{fig:color-button-uml} \end{figure}