function Student(name, age) {
this.name = name;
this.age = age;
}
const stu2 = new Student("tom", 18);
console.log(stu2);
const stu3 = newFn(Student, "tom1", 181);
function newFn(fn, ...args) {
/* const newObj = {};
newObj.__proto__ = fn.prototype; */
const newObj = Object.create(fn.prototype);
const res = fn.apply(newObj, args);
if (res instanceof Object) {
return res;
} else {
return newObj;
}
}
console.log(stu3);
网友评论