JavaScript Tutorial ✦
Factory Function Pattern
Creates objects with shared structure but different implementations.
function createVehicle(type) {
return {
type,
start() {
console.log(`${this.type} started`);
}
};
}
const car = createVehicle('Car');