function isPrimitive(val) {
return val !== Object(val);
}
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
function customNew(constructor, args) {
const self = Object.create({});
const constructorValue = constructor.apply(self, args) || self;
return isPrimitive(constructorValue) ? self : constructorValue;
}
const obj = customNew(Person, ['John', 'Doe']);
console.log(obj);