I have two functions that do the same thing (I may be wrong, but seems like they do the same thing in my newbie opinion):
// Factory Function
function createCircle(radius) {
return {
radius,
draw: function() {
console.log('draw');
}
}
}
const newCircle = createCircle(2);
console.log(newCircle);
And
// Constructor Function
function Circle(radius) {
this.radius = radius;
this.draw = function() {
console.log('draw')
}
}
const another = new Circle(2);
console.log(another);
Are there some pros and cons of these approaches? Just seeking for the opinions of more experienced developers.