What benefit does this factory function provide compared to object literals?
function createPerson(name, age) {
return {
name,
age,
greet() {
return `Hello, my name is ${name}`;
}
};
}
const person1 = createPerson('Alice', 30);
const person2 = createPerson('Bob', 25);
This factory function provides reusable object templates: 1) It standardizes how person objects are created, 2) It ensures all person objects have the same properties and methods, 3) It allows creating multiple objects with different data but consistent structure, 4) It centralizes person creation logic in one place, 5) It prevents repetition of object structure across the codebase, 6) Changes to the object structure need to be made only in one place.