-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs__myblog__js__07.md.js
More file actions
1 lines (1 loc) · 5.72 KB
/
docs__myblog__js__07.md.js
File metadata and controls
1 lines (1 loc) · 5.72 KB
1
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([[77],{re3Y:function(e,n,a){"use strict";a.r(n);var t=a("q1tI"),l=a.n(t),r=a("dEAq"),c=a("H1Ra"),o=l.a.memo((e=>{e.demos;return l.a.createElement(l.a.Fragment,null,l.a.createElement("div",{className:"markdown"},l.a.createElement("h2",{id:"\u51fd\u6570\u67ef\u91cc\u5316"},l.a.createElement(r["AnchorLink"],{to:"#\u51fd\u6570\u67ef\u91cc\u5316","aria-hidden":"true",tabIndex:-1},l.a.createElement("span",{className:"icon icon-link"})),"\u51fd\u6570\u67ef\u91cc\u5316"),l.a.createElement("h3",{id:"\u4ece\u4e00\u9053\u9762\u8bd5\u9898\u8ba4\u8bc6\u5230\u51fd\u6570\u67ef\u91cc\u5316"},l.a.createElement(r["AnchorLink"],{to:"#\u4ece\u4e00\u9053\u9762\u8bd5\u9898\u8ba4\u8bc6\u5230\u51fd\u6570\u67ef\u91cc\u5316","aria-hidden":"true",tabIndex:-1},l.a.createElement("span",{className:"icon icon-link"})),"\u4ece\u4e00\u9053\u9762\u8bd5\u9898\u8ba4\u8bc6\u5230\u51fd\u6570\u67ef\u91cc\u5316\uff01"),l.a.createElement("p",null,"\u5982\u4f55\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570",l.a.createElement("code",null,"add(1)(2)(3)(1)"),"\uff0c\u9996\u5148\u6211\u4eec\u60f3\u5230\u7684\u4f1a\u662f\u95ed\u5305\uff0c\u4e0b\u9762\u662f\u5b9e\u73b0\u7684\u4ee3\u7801\uff1a"),l.a.createElement(c["a"],{code:"function add(x) {\n return function(y) {\n return function(z) {\n return x + y + z;\n };\n };\n}\n\nconsole.log(add(1)(2)(3));",lang:"js"}),l.a.createElement("p",null,"\u8fd9\u6837\u867d\u7136\u80fd\u5b9e\u73b0\uff0c\u4f46\u662f\u5e76\u4e0d\u7075\u6d3b\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u518d\u52a0\u4e0a\u4e00\u4e2a\u6570\u5b57\u53bb\u8ba1\u7b97\u5462\uff1f\u6bd4\u5982\u73b0\u5728\u53d8\u6210",l.a.createElement("code",null,"add(1)(2)(3)(1)"),",\u8fd9\u6837\u4e0a\u9762\u7684\u4ee3\u7801\u5c31\u4f1a\u62a5\u9519\uff0c\u6240\u4ee5\u8fd9\u6837\u7684\u65b9\u6cd5\u53ea\u80fd\u5b9e\u73b0\u7279\u5b9a\u7684\u9700\u6c42\uff0c\u5e76\u4e0d\u80fd\u9002\u7528\u4e8e\u6240\u6709\u3002"),l.a.createElement("p",null,"\u4e0b\u9762\u6211\u4eec\u5c31\u5f00\u59cb\u8bb2\u51fd\u6570\u67ef\u91cc\u5316\uff0c\u901a\u8fc7\u51fd\u6570\u67ef\u91cc\u5316\u6765\u5b9e\u73b0\u4e0a\u9762\u7684\u53ef\u6269\u5c55\u6027\u5f3a\u7684\u9700\u6c42\uff1a"),l.a.createElement("p",null,"\u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\uff0c\u51fd\u6570\u662f\u4e00\u7b49\u516c\u6c11\u3002\u90a3\u4e48\u51fd\u6570\u67ef\u91cc\u5316\u662f\u600e\u6837\u7684\u5462\uff1f"),l.a.createElement("p",null,"\u51fd\u6570\u67ef\u91cc\u5316\u6307\u7684\u662f\u5c06\u80fd\u591f\u63a5\u6536\u591a\u4e2a\u53c2\u6570\u7684\u51fd\u6570\u8f6c\u5316\u4e3a\u63a5\u6536\u5355\u4e00\u53c2\u6570\u7684\u51fd\u6570\uff0c\u5e76\u4e14\u8fd4\u56de\u63a5\u6536\u4f59\u4e0b\u53c2\u6570\u4e14\u8fd4\u56de\u7ed3\u679c\u7684\u65b0\u51fd\u6570\u7684\u6280\u672f\u3002"),l.a.createElement("p",null,"\u51fd\u6570\u67ef\u91cc\u5316\u7684\u4e3b\u8981\u4f5c\u7528\u548c\u7279\u70b9\u5c31\u662f\u53c2\u6570\u590d\u7528\u3001\u63d0\u524d\u8fd4\u56de\u548c\u5ef6\u8fdf\u6267\u884c\u3002"),l.a.createElement("p",null,l.a.createElement("strong",null,"\u901a\u7528\u7248")),l.a.createElement("p",null,l.a.createElement("code",null,"curry")," \u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8981\u52a8\u6001\u521b\u5efa\u67ef\u91cc\u5316\u7684\u51fd\u6570\uff0c\u4f59\u4e0b\u7684\u53c2\u6570\u5b58\u50a8\u5728 ",l.a.createElement("code",null,"args")," \u53d8\u91cf\u4e2d\u3002"),l.a.createElement("p",null,"\u6267\u884c ",l.a.createElement("code",null,"curry")," \u51fd\u6570\u8fd4\u56de\u7684\u51fd\u6570\u63a5\u6536\u65b0\u7684\u53c2\u6570\u4e0e ",l.a.createElement("code",null,"args")," \u53d8\u91cf\u5b58\u50a8\u7684\u53c2\u6570\u5408\u5e76\uff0c\u5e76\u628a\u5408\u5e76\u7684\u53c2\u6570\u4f20\u5165\u7ed9\u67ef\u91cc\u5316\u4e86\u7684\u51fd\u6570\u3002"),l.a.createElement("p",null,"\u4f46\u662f\u53d1\u73b0\u8fd9\u79cd\u65b9\u5f0f\u5e76\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\uff0c\u6211\u4eec\u9700\u8981\u7684\u662f",l.a.createElement("code",null,"add(2)(3)(4)"),"\u8fd9\u79cd\u65b9\u5f0f"),l.a.createElement(c["a"],{code:"const curry = fn =>\n (judge = (...args) =>\n args.length === fn.length\n ? fn(...args)\n : (...arg) => judge(...args, ...arg));\n\nconst add = (a, b, c) => a + b + c;\nconst curryAdd = curry(add);\n\nconsole.log(curryAdd(1)(2)(3)); // 6\nconsole.log(curryAdd(1, 2)(3)); // 6\nconsole.log(curryAdd(1)(2, 3)); // 6",lang:"js"}),l.a.createElement("p",null,"\u4f46\u662f\u8fd8\u662f\u4e0d\u884c\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5fc5\u987b\u77e5\u9053\u51fd\u6570\u53c2\u6570\u7684\u4e2a\u6570\uff0c\u8981\u4e0d\u7136\u4e5f\u4f1a\u62a5\u9519\uff0c"),l.a.createElement("p",null,l.a.createElement("strong",null,"\u6700\u7ec8\u7248")),l.a.createElement(c["a"],{code:"function currying(fn) {\n let args = [];\n return function temp(...newArgs) {\n if (newArgs.length) {\n args = [...args, ...newArgs];\n return temp;\n } else {\n let val = fn.apply(this, args);\n args = []; //\u4fdd\u8bc1\u518d\u6b21\u8c03\u7528\u65f6\u6e05\u7a7a\n return val;\n }\n };\n}\n\nlet addCurry = currying(add);\nconsole.log(addCurry(1)(2)(3)(4, 5)()); //15\nconsole.log(addCurry(1)(2)(3, 4, 5)()); //15\nconsole.log(addCurry(1)(2, 3, 4, 5)()); //15",lang:"js"}),l.a.createElement("h3",{id:"\u53c2\u8003\u94fe\u63a5"},l.a.createElement(r["AnchorLink"],{to:"#\u53c2\u8003\u94fe\u63a5","aria-hidden":"true",tabIndex:-1},l.a.createElement("span",{className:"icon icon-link"})),"\u53c2\u8003\u94fe\u63a5"),l.a.createElement("p",null,l.a.createElement(r["Link"],{to:"https://juejin.cn/post/6844903665308794888"},"\u53c2\u8003\u5730\u5740"))))}));n["default"]=e=>{var n=l.a.useContext(r["context"]),a=n.demos;return l.a.useEffect((()=>{var n;null!==e&&void 0!==e&&null!==(n=e.location)&&void 0!==n&&n.hash&&r["AnchorLink"].scrollToAnchor(decodeURIComponent(e.location.hash.slice(1)))}),[]),l.a.createElement(o,{demos:a})}}}]);