Hi, I’m new to JS and coding in general. Trying to get a better grasp of objects and factory functions. Can someone help explain why the factory function below doesn’t update the output when a property is changed?
//this is a factory function. it is a function that returns a new object
function circleArea(radius = 10) {
return {
radius: radius,
get area(){
return radius ** 2 * Math.PI;
},
};
};
// this is an object made from Factory function
const a = circleArea(12);
console.log(a);
a.radius = 10;
console.log(a.area);
//this function doesn't update the area when radius is changed