How can I adjust a JS constructor to handle a single object or separate parameters? My current approach wrongly assigns object values.
const info = { first: 'Patrick', age: 25, region: 'US' };
function BuildUser(first, age, region) {
if (typeof first === 'object') {
this.first = first.first;
this.age = first.age;
this.region = first.region;
} else {
this.first = first;
this.age = age;
this.region = region;
}
}
console.log(new BuildUser(info));
console.log(new BuildUser('Jack', 52, 'UK'));