| 123456789101112131415161718192021222324252627282930313233343536373839 |
- /**
- * User model with name and email properties
- */
- class User {
- /**
- * Creates a new User instance
- * @param {string} name - User's name
- * @param {string} email - User's email address
- */
- constructor(name, email) {
- this.name = name;
- this.email = email;
- }
- /**
- * Returns a plain object representation of the user
- * @returns {Object} User data as plain object
- */
- toObject() {
- return {
- name: this.name,
- email: this.email
- };
- }
- /**
- * Creates a new User with updated properties (immutable update)
- * @param {Object} updates - Properties to update
- * @returns {User} New User instance with updates applied
- */
- update(updates) {
- return new User(
- updates.name ?? this.name,
- updates.email ?? this.email
- );
- }
- }
- module.exports = User;
|