diff --git a/JavaScript_Sea/new.ts b/JavaScript_Sea/new.ts new file mode 100644 index 0000000..f62064e --- /dev/null +++ b/JavaScript_Sea/new.ts @@ -0,0 +1,20 @@ +/** + * @description 模拟 new + * @date 2022-06-29 + */ + +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); diff --git a/README.md b/README.md index f8ee54b..d48094f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # learn_example -在学习中写过的那些优秀的、有意思的小项目集合 \ No newline at end of file +在学习中写过的那些优秀的、有意思的小项目集合 + +- Axios_Typescript_Encapsulation TypeScript 封装 axios +- BinarySearch 二叉搜索树 +- Dynamic programming 动态规划 +- JavaScript_Sea 对 JavaScript 的一些深入探索尝试 +- Sorting 排序算法 +- Structure_LinkedList 数据结构链表的算法练习 +- Structure_Queue 数据结构队列的算法练习 \ No newline at end of file