What is the benefit of using Object.create() in this factory function?
function createCalculator() {
// Shared methods for all calculators
const proto = {
add(a, b) { return a + b; },
subtract(a, b) { return a - b; },
multiply(a, b) { return a * b; },
divide(a, b) { return a / b; }
};
// Create a new object with proto as its prototype
return Object.create(proto);
}
Using Object.create() creates memory-efficient objects: 1) All calculator instances share the same methods through the prototype chain, 2) Methods are defined once in memory rather than being recreated for each object, 3) This reduces memory consumption when creating multiple calculator objects, 4) It properly separates shared behavior (methods) from instance-specific data, 5) This leverages JavaScript's prototype inheritance without constructor or class syntax, 6) It's a clean way to implement delegation-based inheritance in factory functions.