From 1522711bc36b88b25d3cbb22af67abf28a88188d Mon Sep 17 00:00:00 2001 From: chunbin1 <545360100@qq.com> Date: Thu, 22 Aug 2024 12:39:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20js=E7=9A=84=E8=87=AA=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...js\350\207\252\345\256\236\347\216\260.md" | 151 ++++++++++++++++++ ...7\345\236\213\351\223\276\345\233\276.png" | Bin 0 -> 21780 bytes ...60\351\252\232\346\223\215\344\275\234.md" | 1 + 3 files changed, 152 insertions(+) create mode 100644 "source/_posts/js\350\207\252\345\256\236\347\216\260.md" create mode 100644 "source/_posts/js\350\207\252\345\256\236\347\216\260/\345\216\237\345\236\213\351\223\276\345\233\276.png" diff --git "a/source/_posts/js\350\207\252\345\256\236\347\216\260.md" "b/source/_posts/js\350\207\252\345\256\236\347\216\260.md" new file mode 100644 index 0000000..4dea0a7 --- /dev/null +++ "b/source/_posts/js\350\207\252\345\256\236\347\216\260.md" @@ -0,0 +1,151 @@ +--- +title: js自实现 +code_block_shrink: false +date: 2024-08-22 12:30:45 +updated: 2024-08-22 12:30:45 +excerpt: js的一些api的自实现 +tags: [js] +--- +# js的自实现 +## new的实现 +### 过程 +1. 新建一个对象p,把构造函数中的this设置为对象的变量 +2. 把p的__proto__指向其构造器的原型对象P.prototype +3. 如果构造函数中有`返回值,且返回值为对象,则返回该对象`,否者返回新建的对象 + +{% asset_img 原型链图.png 原型链图 %} + +### 代码实现 +```js +function Person(name, age) { + this.name = name; + this.age = age; +} + +Person.prototype.sayYourName = function() { + console.log("i am" + this.name); +}; + +function New(constructor, ...args) { + let obj = {}; + if (constructor.prototype !== null) { + obj.__proto__ = constructor.prototype; + } + // 执行构造函数 把属性或者方法添加到创建的空对象上 + let ret = constructor.apply(obj, args); + return ret instanceof Object ? ret : obj +} + +const p = New(Person, "sdfs", 12); +p.sayYourName(); +``` + +## call的实现 +### 思路 +1. 将函数设置为对象的方法(this的指向为该对象) +2. 调用该方法 +3. 删除该方法 + +```js +Function.prototype.call2 = function(content = window,...args) { + // this为该方法 + content.fn = this; + let result = content.fn(...args); + delete content.fn; + return result; +} + +const obj = { + name: 'lcb', + age: 24, +} + +function bar(name, age) { + console.(this.name) + console.log(this.age) +} + +console.log(bar.call2(obj)); +``` + +## apply +### 思路 +同call +### 实现 +```js +Function.prototype.apply2 = function(context = window,args) { + context.fn = this; + let obj; + obj = context.fn(args); + delete obj.fn; + return obj; +}; +``` + +## 函数科里化 +### 思路 +1. 如果传入的参数没有到原函数需要的数量 则继续执行curry函数接收参数 +2. 如果参数达到了,则执行科里化了的函数 + +### 实现 +```js +function curry(fn, ...args) { + let length = fn.length; // Function.length 为 函数需要几个参数 + return function(...params){ + newArgs = args.concat(params); + if (newArgs.length < length) { + return curry.call(this,fn,...newArgs); + }else{ + return fn.apply(this,newArgs); + } + } +} + +function multiFn(a, b, c) { + return a * b * c; +} + +let multi = curry(multiFn); +console.log(multi(2)(3)(4)); +console.log(multi(2,3,4)); +console.log(multi(2)(3,4)); +console.log(multi(2,3)(4)); +``` + +## JSON.stringfy +### 思路 +转化类型: +1. Boolean | Number | String 类型会转换为对应的原始类型 +2. undefined、任意函数以及symbol,会被忽略(出现在非数组对象的属性值中时),或者被转换成 null(出现在数组中时) +3. 不可枚举的属性会被忽略 +4. 如果一个对象的属性值通过某种间接的方式指回该对象本身,即循环引用,属性也会被忽略。// todo +5. 递归/循环 + +### 实现 +```js +function jsonStringify(obj) { + let type = typeof obj; + // 判断是否为对象 + if (type === "object") { + let json = []; + let arr = Array.isArray(obj); // 判断数组 + for (let k in obj) { + let v = obj[k]; + let type = typeof v; + if (/string|undefined|function/.test(type)) { + v = '"' + v + '"'; + } else if (type === "object") { + v = jsonStringify(v); + } + json.push((arr ? "" : '"' + k + '":') + String(v)); + } + } else { + if (/string|undefined|function/.test(type)) { + obj = '"' + obj + '"'; + } + return String(obj); + } + return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); +} + +``` diff --git "a/source/_posts/js\350\207\252\345\256\236\347\216\260/\345\216\237\345\236\213\351\223\276\345\233\276.png" "b/source/_posts/js\350\207\252\345\256\236\347\216\260/\345\216\237\345\236\213\351\223\276\345\233\276.png" new file mode 100644 index 0000000000000000000000000000000000000000..5d0ba658a1ed6f476f73890eabda59c1cbd67020 GIT binary patch literal 21780 zcmYg&bx>Q~7i|)PyA_v0vEuGpD5Yqjg1ZFQkK*ob#hn%?P~0^*6qn*ou>vI&*SyQ` zy+7Ve7-kZ3@45S&Eo<$yiPTV2#Koe-0)ardN^j&fK_GA@@MDjG2D~GcSkVLg0=sG| z%7H4!sSiLP8IY2^?0XOJaSmp?>IdXNnkOy4`tW-JLN-sq()VF#g>HOC@od3vmd~HwS@JzIK&HK2)|FA9G z3b(7l9b7~YVff#Ri!fcn)1@Fs{PWymm%o2+MMVYUsm@3ExB4$J7!d&&5i*$s`RVuf zXA=$BB&?GJI*ma=>t6Tq>IM}^%&tQO8(P5ucL5j^m5=~TNDz1gWo2%2KQ8+(-%^g( zI)MD6HbRdqk5jv;*tk0=<2r8`dH+MZW-Ie}xv8o9pE5zV#k{`jm`-SotSnSs1}aaF ziz$PHC3QB+-++9)I|+y|&UwJE5rH6^_I%KXe=B>K)e~<2B49j5ZER z@@Qk$+iHGn1jfIMWll*+Rd~8mD8@#Ck<-yaO#?jvEjg^8#+sHx zVl3sULIwU+g5;HS8S}^BZ3*aIRMOiv`4NZA3tG@Syc4jhfX|~Ls`a}V!oJ42nu@I z z_*}bGZkj|#Hs|1Xcihx4G!s2ENE%@TMyA0j@>_0U|B6bEpDvPs4R)*lH2A9Fc~-Ob zE7|%m5~7Mdq|vDfahm;~p4(4|VGhG~56g*MN&nv46f7sSW;_Zn{2mu}{o?TM-ea$7 z>k*Z**U6eCx*3FELZ>WHdrR3AC%GI^Y0d`ur8Mo=u6GjE)Ud5W;ZKXT7K>K3%l3Nh znY3u1Q{l~7j@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&VrK}fks{(9_0vsnK^H7Ps_R{7lpt6N%O6Kh>$km2S{SjaJp!s%)WGG8Q`^O_ zel-xj5bH{a0<~a?P~4!+VZ9YaYc%jxM8XR53e?doW_t2M=+2P5Z@6lIToN_;C&U%v zl@~buRhGR%o-1ZJd#py~z6XS%7qyTp4H&H-yhTYUbKRIA#|2*UYq7iF#|X21g*fkJ zLC?vpF>(!8zg1*P{Z7h69^-Af<3JO>W}skIX9_x~8~}|3F1{F^Y7GNkO$NLFK*}GvTfSqxn<3#%1c7`0$l}QL#~)4ZUny=elEyDb}ZID+E@UC zHSVHd9^U*}&GjQnvA@336^cLR^G?GJn`a$08g}w9C7=jFak3(ue!ACV^4b49H3OdN zYLxiT{%?n;sxBjd5M6Nudw$0p=lNS=P>L0>o7!ygPHweT#V9B_*C=9oA{6bR#m^_={JcN#0LeE zIzRItJB5CV!SGl22`kyS{e+8v(T&IKN#4}Ev)A@r@_l)5KJf+<+!zsYg##Dh%7m3Y ztT-wk#2lkpW^?F1MiYqU2TX07h$`M)$+2h_ITk$njii=A?h0Lexl~+ z+8@*qO2}u3VOu&wQp2x%MWQ!LD%dcYlU-|;P^_6{FO15VVCi+CAKofEJUFgsS7fx+ z?!HZ7m*DaF`@DV4NmA?csqP_S{+hyB2s0J?BWeUtHUsW=MzVf|=jO$LhS*Q;I-M|0 za&&YIU33~@lukYs9FCwg6V+C|-a3n%96aW{vD6#K2o3hXpa0AXQ1m$0`6kjQqCa)0 SIzXG#O-GHbj4BP?qW%Zfa2*~1 literal 0 HcmV?d00001 diff --git "a/source/_posts/\346\263\233\345\236\213\344\273\216\345\205\245\351\227\250\345\210\260\351\252\232\346\223\215\344\275\234.md" "b/source/_posts/\346\263\233\345\236\213\344\273\216\345\205\245\351\227\250\345\210\260\351\252\232\346\223\215\344\275\234.md" index fae216a..a3dc1fe 100644 --- "a/source/_posts/\346\263\233\345\236\213\344\273\216\345\205\245\351\227\250\345\210\260\351\252\232\346\223\215\344\275\234.md" +++ "b/source/_posts/\346\263\233\345\236\213\344\273\216\345\205\245\351\227\250\345\210\260\351\252\232\346\223\215\344\275\234.md" @@ -3,6 +3,7 @@ title: 泛型从入门到骚操作 excerpt: 介绍了ts泛型infer的使用 tags: TypeScript code_block_shrink: false +date: 2024-07-07 17:02:40 updated: 2024-08-01 11:50:44 --- 泛型可以用来创建可重用的数据类型