// new的四个步骤:
// 1.创建一个新对象
// 2.将该对象的__proto__属性挂载在函数的prototype上
// 3.将函数的this指向该对象
// 4.执行函数 如果函数没有返回引用类型 就返回该对象
function newFactory(func){
if(typeof func!=="function"){
throw new TypeError("this is not a function")
}
let obj = {};
let args = Array.from(arguments).slice(1);
obj.__proto__ = func.prototype;
const result = func.apply(obj,args);
return result instanceof Object?result:obj;
}
function Kemi(name,age){
this.name = name;
this.age = age;
console.log(`Hi! I am ${this.name},I am ${this.age} years old!`);
}
let obj = newFactory(Kemi,"kime",19);
console.log(obj.age)
let obj1 = new Kemi("AX",20);
console