//new function customNew(constructor,...args){ //1.生成新的对象,继承constructor原型 const obj=Object.create(constructor.prototype) //2.把obj当成this,constructor执行,传入参数 constructor.apply(obj,args) //3.返回obj return obj } function Foo(name,city){ this.name=name this.city=city this.getName=()=>{ return this.name } } const f1=new Foo('liu','wuhan') console.log(f1) const f2=customNew(Foo,'mei','wh') console.log(f2)