function myNew(fn, ...rest) {
const obj = Object.create(fn.prototype);
const result = fn.call(obj, ...rest);
return result instanceof Object ? result : obj;
}
function Person(name) {
this.name = name
}
Person.prototype.sayName = function() {
console.log(`My name is ${this.name}`)
}
const me = myNew(Person, 'Jack')
me.sayName()
console.log(me)