Extend a class and create a sub class for easier maintainability. Sub class can make use of special super functions to extend the functionality of a class. Using sub classes you can build out a complex logic in steps rather than as one messy module.
See how to start with a Javascript class and class prototypes if you are new to Javascript classes.
Consider the example from our prototype discussion-
User.prototype.users = []; class UserData { user = { name: "", type: "", }; setUser({ name, type }) { this.user.name = name; this.user.type = type; } addUser() { this.users.push(this.user); } } UserData.prototype.users = []; user1 = new UserData(); user1.setUser({ name: "Rama", type: "Teacher" }); user1.addUser(); console.log(user1.users); // [ { name: 'Rama', type: 'Teacher' } ] user2 = new UserData(); user2.setUser({ name: "Kris", type: "Student" }); user2.addUser(); console.log(user2.users); /* output [ { name: 'Rama', type: 'Teacher' }, { name: 'Kris', type: 'Student' } ] */ console.log(user1.users); // // [ { name: 'Rama', type: 'Teacher' } ] /* output [ { name: 'Rama', type: 'Teacher' }, { name: 'Kris', type: 'Student' } ] */ Our application works beautifully and allows us to define users. But, what if we want to store information specific to teachers and students?
...