function Person(name,age,sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
function newObj(Fn,args) {
let re = {};
if(Fn.prototype !== null){
Object.setPrototypeOf(re,Fn.prototype);//指向Fn的原型
// re = Object.create(Fn.prototype);
}
const result = Fn.call(re,args);//绑定上下文,并返回对象,未绑定成功则返回re
if ((typeof result === "object" || typeof result === "function") && result !== null) {
return result;
}
return re;
}
let person = newObj(Person,['zhuhong','24','man']);
console.log(person);