js factory functions js info code example
Example: factory function javascript
function createPerson(firstName, lastName) {
return {
firstName: this.firstName,
lastName: this.lastName,
getFullName: function () {
return `${this.firstName} ${this.lastName}`
}
}
}
let user = createPerson('John', 'Doe');
console.log(user.getFullName()); // John Doe