function _new(target,...args){
let obj = {};
if(target.prototype !== null){
obj = Object.create(target.prototype);
}
const result = target.apply(obj,args);
if((typeof result === ('object' || 'function')) && result !== null){
console.log("返回值:"+result)
return result;
}
return obj;
}
function Person (name,age){
this.name = name;
this.age = age;
this.say = function () {
console.log("I am " + this.name)
}
return 1;
}
let person1 = new Person("Curry",18);
console.log(person1.name);
console.log(person1.age);
person1.say();
console.log(person1);
let person2 = _new(Person,"Curry",18);
console.log(person2.name);
console.log(person2.age);
person2.say();
console.log(person2);