在学习中写过的那些优秀的、有意思的小项目集合
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

21 lines
447 B

/**
* @description 模拟 new
* @date 2022-06-29
* @article https://zhuanlan.zhihu.com/p/50719681
*/
function Op1(name, age) {
this.name = name;
this.age = age;
}
function myNew(obs: any, ...args) {
const newObject = Object.create(obs.prototype);
const returnObj = obs.apply(newObject, args);
if (!(returnObj instanceof Object)) return newObject;
else return returnObj;
}
const ex1 = myNew(Op1, 1, 1);
console.log("ex1", ex1);