function myNew(fn, ...args) {
if (typeof fn !== 'function') throw 'first argrments need to be a function'
let newObj = Object.create(fn.prototype);
let hasRet = fn.apply(newObj, args);
let isObject = typeof hasRet === 'object' && hasRet !== null;
let isFunction = typeof hasRet === 'function';
if (isObject || isFunction) {
return hasRet
}
return newObj
}
function Person(name, sex) {
this.name = name;
this.sex = sex
}
Person.prototype.getName = function () {
return this.name
}
const pp = new Person('pp', '男');
const mypp = myNew(Person, 'mypp', '男');
console.log('new',pp);
console.log('mynew',mypp);
console.log(pp.getName());
console.log(pp.getName === mypp.getName);
console