function Person(name) {
this.name = name;
return [1, 2, 3];
}
function myNew(constructor, ...rest) {
const obj = Object.create(constructor.prototype);
const res = constructor.call(obj, ...rest);
return res instanceof Object ? res : obj;
}
const obj = myNew(Person, 'xiaohu');
网友评论