Factory & Constructor Functions
Which pattern does this code implement?
const createShape = (type, ...args) => {
const shapes = {
circle: (radius) => ({
type: 'circle',
radius,
area: () => Math.PI * radius * radius
}),
rectangle: (width, height) => ({
type: 'rectangle',
width,
height,
area: () => width * height
})
};
return shapes[type]?.(...args);
};