=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},o=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},f="mdxType",y={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},u=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,p=e.originalType,c=e.parentName,o=l(e,["components","mdxType","originalType","parentName"]),f=s(n),u=a,m=f["".concat(c,".").concat(u)]||f[u]||y[u]||p;return n?r.createElement(m,i(i({ref:t},o),{},{components:n})):r.createElement(m,i({ref:t},o))}));function m(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var p=n.length,i=new Array(p);i[0]=u;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[f]="string"==typeof e?e:a,i[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>y,frontMatter:()=>p,metadata:()=>l,toc:()=>s});var r=n(87462),a=(n(67294),n(3905));const p={sidebar_label:"\u57fa\u7840\uff1aTypeScript \u4e2d\u7684 Interface \u548c Type Alias",sidebar_position:7},i="TypeScript \u4e2d\u7684 Interface \u548c Type Alias",l={unversionedId:"book3/js-ts-interface-type",id:"book3/js-ts-interface-type",title:"TypeScript \u4e2d\u7684 Interface \u548c Type Alias",description:"\u76f8\u5173\u95ee\u9898",source:"@site/docs/book3/js-ts-interface-type.md",sourceDirName:"book3",slug:"/book3/js-ts-interface-type",permalink:"/awesome-interview/book3/js-ts-interface-type",draft:!1,tags:[],version:"current",sidebarPosition:7,frontMatter:{sidebar_label:"\u57fa\u7840\uff1aTypeScript \u4e2d\u7684 Interface \u548c Type Alias",sidebar_position:7},sidebar:"tutorialSidebar",previous:{title:"\u57fa\u7840\uff1aJavaScript \u5f02\u6b65\u7f16\u7a0b",permalink:"/awesome-interview/book3/js-async"},next:{title:"\u6837\u5f0f\uff1a\u79fb\u52a8\u7aef\u81ea\u9002\u5e94\u7684\u5e38\u89c1\u624b\u6bb5",permalink:"/awesome-interview/book3/css-mobile-adaptive"}},c={},s=[{value:"\u76f8\u5173\u95ee\u9898",id:"\u76f8\u5173\u95ee\u9898",level:2},{value:"\u56de\u7b54\u5173\u952e\u70b9",id:"\u56de\u7b54\u5173\u952e\u70b9",level:2},{value:"\u77e5\u8bc6\u70b9\u6df1\u5165",id:"\u77e5\u8bc6\u70b9\u6df1\u5165",level:2},{value:"1. Interface \u548c Type \u7684\u76f8\u540c\u70b9",id:"1-interface-\u548c-type-\u7684\u76f8\u540c\u70b9",level:3},{value:"1.1 \u53ef\u63cf\u8ff0\u5bf9\u8c61/\u51fd\u6570",id:"11-\u53ef\u63cf\u8ff0\u5bf9\u8c61\u51fd\u6570",level:4},{value:"1.2 \u53ef\u6269\u5c55",id:"12-\u53ef\u6269\u5c55",level:4},{value:"1.3 class Implements",id:"13-class-implements",level:4},{value:"2. Interface \u548c Type \u7684\u4e0d\u540c\u70b9",id:"2-interface-\u548c-type-\u7684\u4e0d\u540c\u70b9",level:3},{value:"2.1 \u57fa\u672c\u7c7b\u578b\u522b\u540d\u3001\u8054\u5408\u7c7b\u578b\u3001\u5143\u7ec4",id:"21-\u57fa\u672c\u7c7b\u578b\u522b\u540d\u8054\u5408\u7c7b\u578b\u5143\u7ec4",level:4},{value:"2.2 \u58f0\u660e\u5408\u5e76",id:"22-\u58f0\u660e\u5408\u5e76",level:4},{value:"2.3 \u52a8\u6001\u5c5e\u6027",id:"23-\u52a8\u6001\u5c5e\u6027",level:4},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",level:2}],o={toc:s},f="wrapper";function y(e){let{components:t,...n}=e;return(0,a.kt)(f,(0,r.Z)({},o,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"typescript-\u4e2d\u7684-interface-\u548c-type-alias"},"TypeScript \u4e2d\u7684 Interface \u548c Type Alias"),(0,a.kt)("h2",{id:"\u76f8\u5173\u95ee\u9898"},"\u76f8\u5173\u95ee\u9898"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Interface \u548c Type Alias \u7684\u4f5c\u7528"),(0,a.kt)("li",{parentName:"ul"},"Interface \u548c Type Alias \u7684\u76f8\u540c\u70b9"),(0,a.kt)("li",{parentName:"ul"},"Interface \u548c Type Alias \u7684\u533a\u522b")),(0,a.kt)("h2",{id:"\u56de\u7b54\u5173\u952e\u70b9"},"\u56de\u7b54\u5173\u952e\u70b9"),(0,a.kt)("p",null,(0,a.kt)("inlineCode",{parentName:"p"},"\u7c7b\u578b\u7ea6\u675f")," ",(0,a.kt)("inlineCode",{parentName:"p"},"\u6269\u5c55")," ",(0,a.kt)("inlineCode",{parentName:"p"},"\u7c7b\u578b\u5408\u5e76")),(0,a.kt)("p",null,"Interface \u548c Type Alias\uff08Type \u522b\u540d\uff0c\u4e0b\u6587\u7b80\u79f0 Type\uff09\u662f TypeScript \u4e2d\u4e24\u4e2a\u975e\u5e38\u91cd\u8981\u4e14\u5e38\u7528\u7684\u6982\u5ff5\u3002\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\uff0cInterface \u548c Type \u4e3b\u8981\u8d77\u5230\u7c7b\u578b\u7684\u9650\u5236\u548c\u89c4\u8303\u7684\u4f5c\u7528\uff0c\u5b83\u4eec\u4e0d\u5173\u5fc3\u5b9e\u73b0\u7ec6\u8282\uff0c\u53ea\u89c4\u5b9a\u548c\u9650\u5236\u7c7b\u6216\u53d8\u91cf\u5fc5\u987b\u63d0\u4f9b\u5bf9\u5e94\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002"),(0,a.kt)("p",null,"Interface \u548c Type \u6838\u5fc3\u7684\u533a\u522b\u662f Type \u4e0d\u53ef\u5728\u5b9a\u4e49\u540e\u91cd\u65b0\u6dfb\u52a0\u5185\u5bb9\uff0c\u800c Interface \u5219\u603b\u662f\u53ef\u4ee5\u6269\u5c55\u65b0\u5185\u5bb9\u3002\u76f8\u6bd4 Interface\uff0cType \u5e76\u6ca1\u6709\u5b9e\u9645\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7c7b\u578b\uff0c\u800c\u662f\u521b\u5efa\u4e00\u4e2a\u5f15\u7528\u67d0\u4e2a\u7c7b\u578b\u7684\u540d\u5b57\u3002"),(0,a.kt)("h2",{id:"\u77e5\u8bc6\u70b9\u6df1\u5165"},"\u77e5\u8bc6\u70b9\u6df1\u5165"),(0,a.kt)("p",null,"\u603b\u4f53\u6765\u8bf4\uff0cInterface \u548c Type \u4e24\u8005\u975e\u5e38\u76f8\u4f3c\uff0cInterface \u7684\u7279\u6027\u5927\u90e8\u5206\u90fd\u53ef\u4ee5\u4f7f\u7528 Type \u5b9e\u73b0\uff0c\u5728\u5927\u591a\u6570\u573a\u666f\u4e0b\u90fd\u53ef\u4ee5\u4efb\u610f\u9009\u62e9 Interface \u6216 Type \u5b9e\u73b0\u529f\u80fd\u3002\u6839\u636e\u8fd9\u4e24\u8005\u8bbe\u8ba1\u4e0a\u7684\u5f02\u540c\uff0c\u53ef\u4ee5\u603b\u7ed3\u51fa\u4e24\u8005\u4f7f\u7528\u4e0a\u7684\u76f8\u540c\u70b9\u548c\u4e0d\u540c\u70b9\u3002"),(0,a.kt)("h3",{id:"1-interface-\u548c-type-\u7684\u76f8\u540c\u70b9"},"1. Interface \u548c Type \u7684\u76f8\u540c\u70b9"),(0,a.kt)("h4",{id:"11-\u53ef\u63cf\u8ff0\u5bf9\u8c61\u51fd\u6570"},"1.1 \u53ef\u63cf\u8ff0\u5bf9\u8c61/\u51fd\u6570"),(0,a.kt)("p",null,"Interface \u548c Type \u90fd\u53ef\u4ee5\u63cf\u8ff0\u5bf9\u8c61\u548c\u51fd\u6570\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-typescript"},"// Interface\ninterface IHzfe {\n name: string;\n}\ninterface GetHZFE {\n (): string;\n}\n\n// Type\ntype THzfe = {\n name: string;\n};\ntype GetHZFE = () => string;\n")),(0,a.kt)("h4",{id:"12-\u53ef\u6269\u5c55"},"1.2 \u53ef\u6269\u5c55"),(0,a.kt)("p",null,"Interface \u548c Type \u90fd\u53ef\u4ee5\u6269\u5c55\u7c7b\u578b\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-typescript"},"// Interface\ninterface IHzfe {\n name: string;\n}\ninterface IShfe extends IHzfe {\n location: string;\n}\n\n// Type\ntype THzfe = {\n name: string;\n};\ntype TShfe = THzfe & { location: string };\n")),(0,a.kt)("p",null,"\u53e6\u5916\uff0cInterface \u7684 extends \u548c Type \u7684\u4ea4\u53c9\u7c7b\u578b\u6709\u4e00\u4e9b\u7ec6\u5fae\u533a\u522b\uff1aextends \u4e2d\u7684\u540c\u540d\u5b57\u6bb5\u7684\u7c7b\u578b\u5fc5\u987b\u662f\u517c\u5bb9\u7684\u3002\u800c\u4ea4\u53c9\u7c7b\u578b\u4e2d\u51fa\u73b0\u4e86\u540c\u540d\u5b57\u6bb5\u4e14\u7c7b\u578b\u4e0d\u540c\u65f6\uff0c\u5219\u7c7b\u578b\u4e00\u822c\u662f never\u3002"),(0,a.kt)("h4",{id:"13-class-implements"},"1.3 class Implements"),(0,a.kt)("p",null,"Interface \u548c Type \u63cf\u8ff0\u7684\u7c7b\u578b\u90fd\u53ef\u4ee5\u88ab class \u5b9e\u73b0\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-typescript"},'// Interface\ninterface IHzfe {\n name: string;\n}\n\n// Type\ntype THzfe = {\n name: string;\n};\n\nclass HZFE1 implements IHzfe {\n name = "HZFEStudio";\n}\nclass HZFE2 implements THzfe {\n name = "HZFEStudio";\n}\n')),(0,a.kt)("h3",{id:"2-interface-\u548c-type-\u7684\u4e0d\u540c\u70b9"},"2. Interface \u548c Type \u7684\u4e0d\u540c\u70b9"),(0,a.kt)("h4",{id:"21-\u57fa\u672c\u7c7b\u578b\u522b\u540d\u8054\u5408\u7c7b\u578b\u5143\u7ec4"},"2.1 \u57fa\u672c\u7c7b\u578b\u522b\u540d\u3001\u8054\u5408\u7c7b\u578b\u3001\u5143\u7ec4"),(0,a.kt)("p",null,"\u7531\u4e8e Type \u5b9a\u4e49\u7684\u5b9e\u9645\u662f\u4e00\u4e2a\u522b\u540d\uff0c\u6240\u4ee5 Type \u53ef\u4ee5\u63cf\u8ff0\u4e00\u4e9b\u57fa\u672c\u7c7b\u578b\u3001\u8054\u5408\u7c7b\u578b\u548c\u5143\u7ec4\u7684\u522b\u540d\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-typescript"},"// \u57fa\u672c\u7c7b\u578b\ntype HZFEMember = number;\n\n// \u8054\u5408\u7c7b\u578b\ntype HZFEMemberTechStack = string | string[];\n\n// \u5143\u7ec4\ntype HZFEMember = [number, string];\n")),(0,a.kt)("h4",{id:"22-\u58f0\u660e\u5408\u5e76"},"2.2 \u58f0\u660e\u5408\u5e76"),(0,a.kt)("p",null,"Interface \u53ef\u4ee5\u91cd\u590d\u5b9a\u4e49\uff0c\u5e76\u5c06\u5408\u5e76\u6240\u6709\u58f0\u660e\u7684\u5c5e\u6027\u4e3a\u5355\u4e2a\u63a5\u53e3\u3002\u800c Type \u4e0d\u53ef\u91cd\u590d\u5b9a\u4e49\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-typescript"},'// Interface\ninterface IHzfe {\n name: string;\n}\ninterface IHzfe {\n member: number;\n}\n\nconst hzfe: IHzfe = { name: "HZFE", member: 17 };\n')),(0,a.kt)("h4",{id:"23-\u52a8\u6001\u5c5e\u6027"},"2.3 \u52a8\u6001\u5c5e\u6027"),(0,a.kt)("p",null,"Type \u53ef\u4ee5\u4f7f\u7528 in \u5173\u952e\u5b57\u52a8\u6001\u751f\u6210\u5c5e\u6027\uff0c\u800c Interface \u7684\u7d22\u5f15\u503c\u5fc5\u987b\u662f string \u6216 number \u7c7b\u578b\uff0c\u6240\u4ee5 Interface \u5e76\u4e0d\u652f\u6301\u52a8\u6001\u751f\u6210\u5c5e\u6027\u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-typescript"},'type HZFELanguage = "JavaScript" | "Go";\ntype HZFEProjects = {\n [key in HZFELanguage]?: string[];\n};\n\nconst hzfeProjects: HZFEProjects = {\n JavaScript: ["xx", "xx"],\n};\n')),(0,a.kt)("h2",{id:"\u53c2\u8003\u8d44\u6599"},"\u53c2\u8003\u8d44\u6599"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://www.typescriptlang.org/"},"TypScript - Typed JavaScript at Any Scale"))))}y.isMDXComponent=!0}}]);
--------------------------------------------------------------------------------
/assets/js/8584d295.ebf32f7e.js:
--------------------------------------------------------------------------------
1 | "use strict";(self.webpackChunkjjbook=self.webpackChunkjjbook||[]).push([[7259],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var n=r(67294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function l(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),u=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):l(l({},t),e)),r},c=function(e){var t=u(e.components);return n.createElement(p.Provider,{value:t},e.children)},s="mdxType",k={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),s=u(r),m=a,f=s["".concat(p,".").concat(m)]||s[m]||k[m]||o;return r?n.createElement(f,l(l({ref:t},c),{},{components:r})):n.createElement(f,l({ref:t},c))}));function f(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,l=new Array(o);l[0]=m;var i={};for(var p in t)hasOwnProperty.call(t,p)&&(i[p]=t[p]);i.originalType=e,i[s]="string"==typeof e?e:a,l[1]=i;for(var u=2;u{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>l,default:()=>k,frontMatter:()=>o,metadata:()=>i,toc:()=>u});var n=r(87462),a=(r(67294),r(3905));const o={sidebar_label:"\u57fa\u7840\uff1a\u95ed\u5305\u7684\u4f5c\u7528\u548c\u539f\u7406",sidebar_position:6},l="\u95ed\u5305\u7684\u4f5c\u7528\u548c\u539f\u7406",i={unversionedId:"book1/js-closures",id:"book1/js-closures",title:"\u95ed\u5305\u7684\u4f5c\u7528\u548c\u539f\u7406",description:"\u76f8\u5173\u95ee\u9898",source:"@site/docs/book1/js-closures.md",sourceDirName:"book1",slug:"/book1/js-closures",permalink:"/awesome-interview/book1/js-closures",draft:!1,tags:[],version:"current",sidebarPosition:6,frontMatter:{sidebar_label:"\u57fa\u7840\uff1a\u95ed\u5305\u7684\u4f5c\u7528\u548c\u539f\u7406",sidebar_position:6},sidebar:"tutorialSidebar",previous:{title:"\u6846\u67b6\uff1aVue \u7684 computed \u548c watch \u7684\u533a\u522b",permalink:"/awesome-interview/book1/frame-vue-computed-watch"},next:{title:"\u57fa\u7840\uff1a\u524d\u7aef\u6a21\u5757\u5316\u89c4\u8303",permalink:"/awesome-interview/book1/js-module-specs"}},p={},u=[{value:"\u76f8\u5173\u95ee\u9898",id:"\u76f8\u5173\u95ee\u9898",level:2},{value:"\u56de\u7b54\u5173\u952e\u70b9",id:"\u56de\u7b54\u5173\u952e\u70b9",level:2},{value:"\u77e5\u8bc6\u70b9\u6df1\u5165",id:"\u77e5\u8bc6\u70b9\u6df1\u5165",level:2},{value:"1. \u4f5c\u7528\u57df",id:"1-\u4f5c\u7528\u57df",level:3},{value:"2. \u4ec0\u4e48\u662f\u95ed\u5305",id:"2-\u4ec0\u4e48\u662f\u95ed\u5305",level:3},{value:"3. \u95ed\u5305\u7684\u5e94\u7528",id:"3-\u95ed\u5305\u7684\u5e94\u7528",level:3},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",level:2}],c={toc:u},s="wrapper";function k(e){let{components:t,...r}=e;return(0,a.kt)(s,(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"\u95ed\u5305\u7684\u4f5c\u7528\u548c\u539f\u7406"},"\u95ed\u5305\u7684\u4f5c\u7528\u548c\u539f\u7406"),(0,a.kt)("h2",{id:"\u76f8\u5173\u95ee\u9898"},"\u76f8\u5173\u95ee\u9898"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"\u4ec0\u4e48\u662f\u95ed\u5305"),(0,a.kt)("li",{parentName:"ul"},"\u95ed\u5305\u7684\u5e94\u7528")),(0,a.kt)("h2",{id:"\u56de\u7b54\u5173\u952e\u70b9"},"\u56de\u7b54\u5173\u952e\u70b9"),(0,a.kt)("p",null,(0,a.kt)("inlineCode",{parentName:"p"},"\u4f5c\u7528\u57df")," ",(0,a.kt)("inlineCode",{parentName:"p"},"\u5f15\u7528")," ",(0,a.kt)("inlineCode",{parentName:"p"},"\u51fd\u6570")),(0,a.kt)("p",null,"\u4f5c\u7528\uff1a\u80fd\u591f\u5728\u51fd\u6570\u5b9a\u4e49\u7684\u4f5c\u7528\u57df\u5916\uff0c\u4f7f\u7528\u51fd\u6570\u5b9a\u4e49\u4f5c\u7528\u57df\u5185\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u5e76\u4e14\u4e0d\u4f1a\u6c61\u67d3\u5168\u5c40\u3002"),(0,a.kt)("p",null,"\u539f\u7406\uff1a\u57fa\u4e8e\u8bcd\u6cd5\u4f5c\u7528\u57df\u94fe\u548c\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u901a\u8fc7\u7ef4\u6301\u51fd\u6570\u4f5c\u7528\u57df\u7684\u5f15\u7528\uff0c\u8ba9\u51fd\u6570\u4f5c\u7528\u57df\u53ef\u4ee5\u5728\u5f53\u524d\u4f5c\u7528\u57df\u5916\u88ab\u8bbf\u95ee\u5230\u3002"),(0,a.kt)("h2",{id:"\u77e5\u8bc6\u70b9\u6df1\u5165"},"\u77e5\u8bc6\u70b9\u6df1\u5165"),(0,a.kt)("h3",{id:"1-\u4f5c\u7528\u57df"},"1. \u4f5c\u7528\u57df"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("strong",{parentName:"li"},"\u4f5c\u7528\u57df"),"\uff1a\u7528\u4e8e\u786e\u5b9a\u5728\u4f55\u5904\u4ee5\u53ca\u5982\u4f55\u67e5\u627e\u53d8\u91cf\uff08\u6807\u8bc6\u7b26\uff09\u7684\u4e00\u5957\u89c4\u5219\u3002"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("strong",{parentName:"li"},"\u8bcd\u6cd5\u4f5c\u7528\u57df"),"\uff1a\u8bcd\u6cd5\u4f5c\u7528\u57df\u662f",(0,a.kt)("strong",{parentName:"li"},"\u5b9a\u4e49\u5728\u8bcd\u6cd5\u9636\u6bb5\u7684\u4f5c\u7528\u57df"),"\u3002\u8bcd\u6cd5\u4f5c\u7528\u57df\u662f\u7531\u5199\u4ee3\u7801\u65f6\u5c06\u4ee3\u7801\u548c\u5757\u4f5c\u7528\u57df\u5199\u5728\u54ea\u91cc\u6765\u51b3\u5b9a\u7684\uff0c\u56e0\u6b64\u5f53\u8bcd\u6cd5\u4f5c\u7528\u57df\u5904\u7406\u4ee3\u7801\u662f\u4f1a\u4fdd\u6301\u4f5c\u7528\u57df\u4e0d\u53d8(\u5927\u90e8\u5206\u60c5\u51b5)\u3002"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("strong",{parentName:"li"},"\u5757\u4f5c\u7528\u57df"),"\uff1a\u6307\u7684\u662f\u53d8\u91cf\u548c\u51fd\u6570\u4e0d\u4ec5\u53ef\u4ee5\u5c5e\u4e8e\u6240\u5904\u7684\u4f5c\u7528\u57df\uff0c\u4e5f\u53ef\u4ee5\u5c5e\u4e8e\u67d0\u4e2a\u4ee3\u7801\u5757\uff08\u901a\u5e38\u7528{}\u5305\u88f9\uff09\u3002\u5e38\u89c1\u7684\u5757\u7ea7\u4f5c\u7528\u57df\u6709 with\uff0ctry/catch\uff0clet\uff0cconst \u7b49\u3002"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("strong",{parentName:"li"},"\u51fd\u6570\u4f5c\u7528\u57df"),"\uff1a\u5c5e\u4e8e\u8fd9\u4e2a\u51fd\u6570\u7684\u5168\u90e8\u53d8\u91cf\u90fd\u53ef\u4ee5\u5728\u6574\u4e2a\u51fd\u6570\u8303\u56f4\u5185\u4f7f\u7528\u53ca\u590d\u7528\uff08\u5305\u62ec\u5d4c\u5957\u4f5c\u7528\u57df\uff09\u3002"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("strong",{parentName:"li"},"\u4f5c\u7528\u57df\u94fe"),"\uff1a\u67e5\u627e\u53d8\u91cf\u65f6\uff0c\u5148\u4ece\u5f53\u524d\u4f5c\u7528\u57df\u5f00\u59cb\u67e5\u627e\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230\uff0c\u5c31\u4f1a\u5230\u7236\u7ea7(\u8bcd\u6cd5\u5c42\u9762\u4e0a\u7684\u7236\u7ea7)\u4f5c\u7528\u57df\u4e2d\u67e5\u627e\uff0c\u4e00\u76f4\u627e\u5230\u5168\u5c40\u4f5c\u7528\u57df\u3002\u4f5c\u7528\u57df\u94fe\u6b63\u662f\u5305\u542b\u8fd9\u4e9b\u4f5c\u7528\u57df\u7684\u5217\u8868\u3002")),(0,a.kt)("h3",{id:"2-\u4ec0\u4e48\u662f\u95ed\u5305"},"2. \u4ec0\u4e48\u662f\u95ed\u5305"),(0,a.kt)("blockquote",null,(0,a.kt)("p",{parentName:"blockquote"},"\u5f53\u51fd\u6570\u53ef\u4ee5\u8bb0\u4f4f\u5e76\u8bbf\u95ee\u6240\u5728\u7684\u8bcd\u6cd5\u4f5c\u7528\u57df\u65f6\uff0c\u5c31\u4ea7\u751f\u4e86\u95ed\u5305\uff0c\u5373\u4f7f\u662f\u51fd\u6570\u5728\u5f53\u524d\u8bcd\u6cd5\u4f5c\u7528\u57df\u5916\u6267\u884c\u3002 \u2014\u2014\u300a\u4f60\u4e0d\u77e5\u9053\u7684 JavaScript\u300b")),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},'function foo() {\n var a = "hzfe";\n function bar() {\n console.log(a);\n }\n return bar;\n}\n\nvar baz = foo();\nbaz(); // hzfe\n')),(0,a.kt)("p",null,"\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u51fd\u6570 bar \u4f5c\u4e3a\u8fd4\u56de\u503c\u8fd4\u56de\u540e\uff0c\u5728\u81ea\u5df1\u5b9a\u4e49\u7684\u8bcd\u6cd5\u4f5c\u7528\u57df\u4ee5\u5916\u7684\u5730\u65b9\u6267\u884c\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5728\u51fd\u6570 foo \u6267\u884c\u540e\uff0c\u901a\u5e38\u4f1a\u671f\u5f85\u51fd\u6570 foo \u7684\u6574\u4e2a\u5185\u90e8\u4f5c\u7528\u57df\u88ab\u5f15\u64ce\u56de\u6536\u673a\u5236\u9500\u6bc1\u3002\u800c\u95ed\u5305\u53ef\u4ee5\u963b\u6b62\u8fd9\u4ef6\u4e8b\u60c5\u7684\u53d1\u751f\u3002\u4e8b\u5b9e\u4e0a\u5185\u90e8\u4f5c\u7528\u57df\u4f9d\u7136\u5b58\u5728\uff0c\u56e0\u4e3a\u51fd\u6570 bar \u672c\u8eab\u5728\u4f7f\u7528\uff0c\u6240\u4ee5\u5e76\u4e0d\u4f1a\u88ab\u56de\u6536\u3002"),(0,a.kt)("p",null,"\u5728 JavaScript \u4e2d\uff0c",(0,a.kt)("strong",{parentName:"p"},"\u6bcf\u5f53\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u95ed\u5305\u5c31\u4f1a\u5728\u51fd\u6570\u521b\u5efa\u7684\u540c\u65f6\u88ab\u521b\u5efa\u51fa\u6765"),"\u3002"),(0,a.kt)("h3",{id:"3-\u95ed\u5305\u7684\u5e94\u7528"},"3. \u95ed\u5305\u7684\u5e94\u7528"),(0,a.kt)("p",null,"\u65e0\u8bba\u4f55\u65f6\u4f55\u5730\uff0c\u5982\u679c",(0,a.kt)("strong",{parentName:"p"},"\u5c06\u51fd\u6570\u4f5c\u4e3a\u8fd4\u56de\u503c\uff0c\u5c31\u4f1a\u770b\u5230\u95ed\u5305\u5728\u8fd9\u4e9b\u51fd\u6570\u4e2d\u7684\u5e94\u7528"),"\u3002\u5728\u5b9a\u65f6\u5668\uff0c\u4e8b\u4ef6\u76d1\u542c\u5668\uff0cajax \u8bf7\u6c42\uff0c\u8de8\u7a97\u53e3\u901a\u4fe1\uff0cweb workers \u6216\u8005\u4efb\u4f55\u5176\u4ed6\u7684\u5f02\u6b65/\u540c\u6b65\u4efb\u52a1\u4e2d\uff0c\u53ea\u8981",(0,a.kt)("strong",{parentName:"p"},"\u4f7f\u7528\u4e86\u56de\u8c03\u51fd\u6570\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u4f7f\u7528\u95ed\u5305"),"\u3002\u4f7f\u7528\u95ed\u5305\u7684\u4f8b\u5b50\u53ef\u4ee5\u53c2\u8003",(0,a.kt)("a",{parentName:"p",href:"/awesome-interview/book2/coding-throttle-debounce"},"\u5b9e\u73b0\u8282\u6d41\u9632\u6296\u51fd\u6570"),"\u3002"),(0,a.kt)("p",null,(0,a.kt)("strong",{parentName:"p"},"TIPS: \u95ed\u5305\u4e0e\u6267\u884c\u51fd\u6570\u5173\u7cfb")),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-javascript"},'var a = "hzfe";\n(function IIFE() {\n console.log(a);\n})();\n')),(0,a.kt)("p",null,"\u901a\u5e38\u8ba4\u4e3a\u7acb\u5373\u6267\u884c\u51fd\u6570\uff08IIFE\uff09\u662f\u5178\u578b\u7684\u89c2\u5bdf\u95ed\u5305\u7684\u5178\u578b\u4f8b\u5b50\uff0c\u4f46\u4e25\u683c\u6765\u8bf4\u5e76\u4e0d\u662f\u3002",(0,a.kt)("strong",{parentName:"p"},"\u867d\u7136\u521b\u5efa\u4e86\u95ed\u5305\uff0c\u4f46\u6ca1\u6709\u4f53\u73b0\u51fa\u95ed\u5305\u7684\u4f5c\u7528"),"\u3002\u56e0\u4e3a\u51fd\u6570\u5e76\u4e0d\u662f\u5728\u5b83\u672c\u8eab\u7684\u8bcd\u6cd5\u4f5c\u7528\u57df\u4ee5\u5916\u6267\u884c\u7684\u3002\n\u5b83\u5728\u5b9a\u4e49\u65f6\u6240\u5728\u7684\u4f5c\u7528\u57df\u4e2d\u6267\u884c\uff0c\u800c\u975e\u5916\u90e8\u4f5c\u7528\u57df\u3002"),(0,a.kt)("h2",{id:"\u53c2\u8003\u8d44\u6599"},"\u53c2\u8003\u8d44\u6599"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Closures"},"\u95ed\u5305 MDN")),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"/awesome-interview/book2/browser-garbage"},"\u5783\u573e\u56de\u6536\u673a\u5236")),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://github.com/getify/You-Dont-Know-JS"},"\u4f60\u4e0d\u77e5\u9053\u7684 JavaScript\uff08\u4e0a\u5377\uff09")),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://zh.wikipedia.org/wiki/%E9%97%AD%E5%8C%85_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)"},"\u7ef4\u57fa\u767e\u79d1-\u95ed\u5305"))))}k.isMDXComponent=!0}}]);
--------------------------------------------------------------------------------
/assets/js/abf449ea.b1986ef7.js:
--------------------------------------------------------------------------------
1 | "use strict";(self.webpackChunkjjbook=self.webpackChunkjjbook||[]).push([[4501],{3905:(e,n,t)=>{t.d(n,{Zo:()=>s,kt:()=>f});var r=t(67294);function l(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function i(e){for(var n=1;n=0||(l[t]=e[t]);return l}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(l[t]=e[t])}return l}var p=r.createContext({}),c=function(e){var n=r.useContext(p),t=n;return e&&(t="function"==typeof e?e(n):i(i({},n),e)),t},s=function(e){var n=c(e.components);return r.createElement(p.Provider,{value:n},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},g=r.forwardRef((function(e,n){var t=e.components,l=e.mdxType,a=e.originalType,p=e.parentName,s=o(e,["components","mdxType","originalType","parentName"]),u=c(t),g=l,f=u["".concat(p,".").concat(g)]||u[g]||d[g]||a;return t?r.createElement(f,i(i({ref:n},s),{},{components:t})):r.createElement(f,i({ref:n},s))}));function f(e,n){var t=arguments,l=n&&n.mdxType;if("string"==typeof e||l){var a=t.length,i=new Array(a);i[0]=g;var o={};for(var p in n)hasOwnProperty.call(n,p)&&(o[p]=n[p]);o.originalType=e,o[u]="string"==typeof e?e:l,i[1]=o;for(var c=2;c{t.r(n),t.d(n,{assets:()=>p,contentTitle:()=>i,default:()=>d,frontMatter:()=>a,metadata:()=>o,toc:()=>c});var r=t(87462),l=(t(67294),t(3905));const a={sidebar_label:"\u7f16\u7801\uff1a\u5b9e\u73b0 apply/call/bind",sidebar_position:10},i="\u5b9e\u73b0 apply/call/bind",o={unversionedId:"book4/coding-apply-call-bind",id:"book4/coding-apply-call-bind",title:"\u5b9e\u73b0 apply/call/bind",description:"apply",source:"@site/docs/book4/coding-apply-call-bind.md",sourceDirName:"book4",slug:"/book4/coding-apply-call-bind",permalink:"/awesome-interview/book4/coding-apply-call-bind",draft:!1,tags:[],version:"current",sidebarPosition:10,frontMatter:{sidebar_label:"\u7f16\u7801\uff1a\u5b9e\u73b0 apply/call/bind",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"\u6837\u5f0f\uff1a\u6c34\u5e73\u5782\u76f4\u5c45\u4e2d\u65b9\u6848",permalink:"/awesome-interview/book4/css-vertical-horizontal-center"},next:{title:"\u7b97\u6cd5\uff1a\u627e\u5230\u6570\u7ec4\u4e2d\u91cd\u590d\u7684\u6570\u5b57",permalink:"/awesome-interview/book4/array-repeat-number"}},p={},c=[{value:"apply",id:"apply",level:2},{value:"1. \u8bed\u6cd5",id:"1-\u8bed\u6cd5",level:3},{value:"2. \u6d41\u7a0b\u56fe",id:"2-\u6d41\u7a0b\u56fe",level:3},{value:"3. \u7f16\u5199\u4ee3\u7801",id:"3-\u7f16\u5199\u4ee3\u7801",level:3},{value:"call",id:"call",level:2},{value:"1. \u8bed\u6cd5",id:"1-\u8bed\u6cd5-1",level:3},{value:"2. \u6d41\u7a0b\u56fe",id:"2-\u6d41\u7a0b\u56fe-1",level:3},{value:"3. \u7f16\u5199\u4ee3\u7801",id:"3-\u7f16\u5199\u4ee3\u7801-1",level:3},{value:"bind",id:"bind",level:2},{value:"1. \u8bed\u6cd5",id:"1-\u8bed\u6cd5-2",level:3},{value:"2. \u6d41\u7a0b\u56fe",id:"2-\u6d41\u7a0b\u56fe-2",level:3},{value:"3. \u7f16\u5199\u4ee3\u7801",id:"3-\u7f16\u5199\u4ee3\u7801-2",level:3},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",level:2}],s={toc:c},u="wrapper";function d(e){let{components:n,...t}=e;return(0,l.kt)(u,(0,r.Z)({},s,t,{components:n,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"\u5b9e\u73b0-applycallbind"},"\u5b9e\u73b0 apply/call/bind"),(0,l.kt)("h2",{id:"apply"},"apply"),(0,l.kt)("h3",{id:"1-\u8bed\u6cd5"},"1. \u8bed\u6cd5"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-jsx"},"func.apply(thisArg, [argsArray]);\n")),(0,l.kt)("p",null,(0,l.kt)("strong",{parentName:"p"},"\u53c2\u6570")),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"thisArg")),(0,l.kt)("p",null,"\u5728 func \u51fd\u6570\u8fd0\u884c\u65f6\u4f7f\u7528\u7684 this \u503c\u3002"),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"argsArray")),(0,l.kt)("p",null,"\u4e00\u4e2a\u6570\u7ec4\u6216\u8005\u7c7b\u6570\u7ec4\u5bf9\u8c61\uff0c\u5176\u4e2d\u7684\u6570\u7ec4\u5143\u7d20\u5c06\u4f5c\u4e3a\u5355\u72ec\u7684\u53c2\u6570\u4f20\u7ed9 func \u51fd\u6570\u3002\u5982\u679c\u8be5\u53c2\u6570\u7684\u503c\u4e3a null \u6216 undefined\uff0c\u5219\u8868\u793a\u4e0d\u9700\u8981\u4f20\u5165\u4efb\u4f55\u53c2\u6570\u3002"),(0,l.kt)("p",null,(0,l.kt)("strong",{parentName:"p"},"\u8fd4\u56de\u503c")),(0,l.kt)("p",null,"\u4f7f\u7528\u6307\u5b9a\u7684 this \u503c\u548c\u53c2\u6570\u8c03\u7528\u51fd\u6570\u7684\u7ed3\u679c\u3002"),(0,l.kt)("h3",{id:"2-\u6d41\u7a0b\u56fe"},"2. \u6d41\u7a0b\u56fe"),(0,l.kt)("p",null,(0,l.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17525377/147632530-34eac628-0bbd-4025-890b-2596a421263d.jpg",alt:"apply"})),(0,l.kt)("h3",{id:"3-\u7f16\u5199\u4ee3\u7801"},"3. \u7f16\u5199\u4ee3\u7801"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-jsx"},'Function.prototype.apply = function (thisArg, argsArray) {\n if (typeof this !== "function") {\n throw new TypeError(\n "Function.prototype.apply was called on which is not a function"\n );\n }\n\n if (thisArg === undefined || thisArg === null) {\n thisArg = window;\n } else {\n thisArg = Object(thisArg);\n }\n\n // \u5c06 func \u653e\u5165 thisArg \u5185\uff0c\u8fd9\u6837\u5728\u8c03\u7528 thisArg[func] \u65f6 this \u81ea\u7136\u5c31\u6307\u5411\u4e86 thisArg\n const func = Symbol("func");\n thisArg[func] = this;\n\n let result;\n\n if (argsArray && typeof argsArray === "object" && "length" in argsArray) {\n // \u6b64\u5904\u4f7f\u7528 Array.from \u5305\u88f9\u8ba9\u5176\u652f\u6301\u5f62\u5982 { length: 1, 0: 1 } \u8fd9\u6837\u7684\u7c7b\u6570\u7ec4\u5bf9\u8c61\uff0c\u76f4\u63a5\u5bf9 argsArray \u5c55\u5f00\u5c06\u4f1a\u6267\u884c\u51fa\u9519\n result = thisArg[func](...Array.from(argsArray));\n } else if (argsArray === undefined || argsArray === null) {\n result = thisArg[func]();\n } else {\n throw new TypeError("CreateListFromArrayLike called on non-object");\n }\n\n delete thisArg[func];\n\n return result;\n};\n')),(0,l.kt)("h2",{id:"call"},"call"),(0,l.kt)("h3",{id:"1-\u8bed\u6cd5-1"},"1. \u8bed\u6cd5"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-jsx"},"func.call(thisArg, arg1, arg2, ...)\n")),(0,l.kt)("p",null,(0,l.kt)("strong",{parentName:"p"},"\u53c2\u6570")),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"thisArg")),(0,l.kt)("p",null,"\u5728 func \u51fd\u6570\u8fd0\u884c\u65f6\u4f7f\u7528\u7684 this \u503c\u3002"),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"arg1, arg2, ...")),(0,l.kt)("p",null,"\u6307\u5b9a\u7684\u53c2\u6570\u5217\u8868\u3002"),(0,l.kt)("p",null,(0,l.kt)("strong",{parentName:"p"},"\u8fd4\u56de\u503c")),(0,l.kt)("p",null,"\u4f7f\u7528\u6307\u5b9a\u7684 this \u503c\u548c\u53c2\u6570\u8c03\u7528\u51fd\u6570\u7684\u7ed3\u679c\u3002"),(0,l.kt)("h3",{id:"2-\u6d41\u7a0b\u56fe-1"},"2. \u6d41\u7a0b\u56fe"),(0,l.kt)("p",null,(0,l.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17525377/147632668-575c348e-96f5-4088-8cee-38e3ee70a2cc.jpg",alt:"call"})),(0,l.kt)("h3",{id:"3-\u7f16\u5199\u4ee3\u7801-1"},"3. \u7f16\u5199\u4ee3\u7801"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-jsx"},'Function.prototype.call = function (thisArg, ...argsArray) {\n if (typeof this !== "function") {\n throw new TypeError(\n "Function.prototype.call was called on which is not a function"\n );\n }\n\n if (thisArg === undefined || thisArg === null) {\n thisArg = window;\n } else {\n thisArg = Object(thisArg);\n }\n\n // \u5c06 func \u653e\u5165 thisArg \u5185\uff0c\u8fd9\u6837\u5728\u8c03\u7528 thisArg[func] \u65f6 this \u81ea\u7136\u5c31\u6307\u5411\u4e86 thisArg\n const func = Symbol("func");\n thisArg[func] = this;\n\n let result;\n\n if (argsArray.length) {\n result = thisArg[func](...argsArray);\n } else {\n result = thisArg[func]();\n }\n\n delete thisArg[func];\n\n return result;\n};\n')),(0,l.kt)("h2",{id:"bind"},"bind"),(0,l.kt)("h3",{id:"1-\u8bed\u6cd5-2"},"1. \u8bed\u6cd5"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-jsx"},"func.bind(thisArg[, arg1[, arg2[, ...]]])\n")),(0,l.kt)("p",null,(0,l.kt)("strong",{parentName:"p"},"\u53c2\u6570")),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"thisArg")),(0,l.kt)("p",null,"\u8c03\u7528\u7ed1\u5b9a\u51fd\u6570\u65f6\u4f5c\u4e3a this \u53c2\u6570\u4f20\u9012\u7ed9\u76ee\u6807\u51fd\u6570\u7684\u503c\u3002 \u5982\u679c\u4f7f\u7528 new \u8fd0\u7b97\u7b26\u6784\u9020\u7ed1\u5b9a\u51fd\u6570\uff0c\u5219\u5ffd\u7565\u8be5\u503c\u3002"),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"arg1, arg2, ...")),(0,l.kt)("p",null,"\u5f53\u76ee\u6807\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u88ab\u9884\u7f6e\u5165\u7ed1\u5b9a\u51fd\u6570\u7684\u53c2\u6570\u5217\u8868\u4e2d\u7684\u53c2\u6570\u3002"),(0,l.kt)("p",null,(0,l.kt)("strong",{parentName:"p"},"\u8fd4\u56de\u503c")),(0,l.kt)("p",null,"\u8fd4\u56de\u4e00\u4e2a\u539f\u51fd\u6570\u7684\u62f7\u8d1d\uff0c\u5e76\u62e5\u6709\u6307\u5b9a\u7684 this \u503c\u548c\u521d\u59cb\u53c2\u6570\u3002"),(0,l.kt)("h3",{id:"2-\u6d41\u7a0b\u56fe-2"},"2. \u6d41\u7a0b\u56fe"),(0,l.kt)("p",null,(0,l.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17525377/147632692-d7d335a7-a236-4bee-85a6-51aedbf285b9.jpg",alt:"bind"})),(0,l.kt)("h3",{id:"3-\u7f16\u5199\u4ee3\u7801-2"},"3. \u7f16\u5199\u4ee3\u7801"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-jsx"},'Function.prototype.bind = function (thisArg, ...argsArray) {\n if (typeof this !== "function") {\n throw new TypeError(\n "Function.prototype.bind was called on which is not a function"\n );\n }\n\n if (thisArg === undefined || thisArg === null) {\n thisArg = window;\n } else {\n thisArg = Object(thisArg);\n }\n\n const func = this;\n\n const bound = function (...boundArgsArray) {\n let isNew = false;\n\n // \u5982\u679c func \u4e0d\u662f\u6784\u9020\u5668\uff0c\u76f4\u63a5\u4f7f\u7528 instanceof \u5c06\u51fa\u9519\uff0c\u6240\u4ee5\u9700\u8981\u7528 try...catch \u5305\u88f9\n try {\n isNew = this instanceof func;\n } catch (error) {}\n\n return func.apply(isNew ? this : thisArg, argsArray.concat(boundArgsArray));\n };\n\n const Empty = function () {};\n Empty.prototype = this.prototype;\n bound.prototype = new Empty();\n\n return bound;\n};\n')),(0,l.kt)("h2",{id:"\u53c2\u8003\u8d44\u6599"},"\u53c2\u8003\u8d44\u6599"),(0,l.kt)("ol",null,(0,l.kt)("li",{parentName:"ol"},(0,l.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply"},"Function.prototype.apply()")),(0,l.kt)("li",{parentName:"ol"},(0,l.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call"},"Function.prototype.call()")),(0,l.kt)("li",{parentName:"ol"},(0,l.kt)("a",{parentName:"li",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind"},"Function.prototype.bind()"))))}d.isMDXComponent=!0}}]);
--------------------------------------------------------------------------------
/about.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 关于我们 | HZFE - 剑指前端 Offer
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
On this page
关于我们 Hi,我们是 HZFE,一群来自于五湖四海的 90 后技术人。
一群固定的人总聚在一起,不知不觉就会成为一个所谓的团队。而我们的团队代号“HZFE”,总让不明其意的人拼错或不知如何发音。曾经在我们三周年活动蛋糕上,店家就用心写下了“H2FF 三周年快乐”的祝福。但是问题不大,只要我们不说,没有人会知道。
我们最初相识于拥有 17 位成员的群聊,群聊名称正是 HZFE。其本意是杭州前端(Hangzhou Front-End),所以也读作“杭州 FE”。尽管我们大多不在杭州,也不全是前端。所以姑且当这是个没道理的代号吧,而我们的相聚则是一场有趣的缘分。
和每个普通人一样,我们大多过着三点一线的生活。喜欢旅游也爱摄影,也像千千万个理财小白一般,在正向或是反向理财中来回波动。每天都在产出新的想法,一起头脑风暴,结局总是以没有设计师为借口不了了之,三分钟热度成了我们心照不宣的默契。每天都在做梦,讲些不切实际的幻想,平凡且平庸。
如果说,唯一值得小小炫耀一番的,便是我们这群人对于热爱开发这件事达成了共识。不论是做开源、做自己的产品亦或各自在工作岗位上,都有所收获和成绩。目前团队开源的技术项目累计 6k star 以上,成员主要任职于腾讯、阿里巴巴、字节跳动、百度等一二线互联网公司,同时也不乏优秀的个人开发者。或许我们也是幸运的,在刚踏入社会时相遇相知相爱,彼此影响,一同成长为此刻至少技术还不赖的人。
因缘巧合下,在某天如同往日的头脑风暴中,我们一拍脑袋,说要一起写本书,将五年来对于行业面试规则和趋势的了解整理成册。就此,开启了这场坎坷的写作之旅。
正如其名:剑指前端 Offer,希望在这本书的帮助下,我们和读者都能有所成长。
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/assets/js/1be78505.418dd524.js:
--------------------------------------------------------------------------------
1 | "use strict";(self.webpackChunkjjbook=self.webpackChunkjjbook||[]).push([[9514,4972],{19963:(e,t,n)=>{n.r(t),n.d(t,{default:()=>pe});var a=n(67294),o=n(86010),l=n(10833),r=n(35281),i=n(43320),c=n(52802),s=n(74477),d=n(1116),m=n(31735),u=n(95999),b=n(12466),p=n(85936);const h={backToTopButton:"backToTopButton_sjWU",backToTopButtonShow:"backToTopButtonShow_xfvO"};function E(){const{shown:e,scrollToTop:t}=function(e){let{threshold:t}=e;const[n,o]=(0,a.useState)(!1),l=(0,a.useRef)(!1),{startScroll:r,cancelScroll:i}=(0,b.Ct)();return(0,b.RF)(((e,n)=>{let{scrollY:a}=e;const r=n?.scrollY;r&&(l.current?l.current=!1:a>=r?(i(),o(!1)):a{e.location.hash&&(l.current=!0,o(!1))})),{shown:n,scrollToTop:()=>r(0)}}({threshold:300});return a.createElement("button",{"aria-label":(0,u.I)({id:"theme.BackToTopButton.buttonAriaLabel",message:"Scroll back to top",description:"The ARIA label for the back to top button"}),className:(0,o.Z)("clean-btn",r.k.common.backToTopButton,h.backToTopButton,e&&h.backToTopButtonShow),type:"button",onClick:t})}var f=n(16550),g=n(87524),v=n(86668),k=n(21327),_=n(87462);function C(e){return a.createElement("svg",(0,_.Z)({width:"20",height:"20","aria-hidden":"true"},e),a.createElement("g",{fill:"#7a7a7a"},a.createElement("path",{d:"M9.992 10.023c0 .2-.062.399-.172.547l-4.996 7.492a.982.982 0 01-.828.454H1c-.55 0-1-.453-1-1 0-.2.059-.403.168-.551l4.629-6.942L.168 3.078A.939.939 0 010 2.528c0-.548.45-.997 1-.997h2.996c.352 0 .649.18.828.45L9.82 9.472c.11.148.172.347.172.55zm0 0"}),a.createElement("path",{d:"M19.98 10.023c0 .2-.058.399-.168.547l-4.996 7.492a.987.987 0 01-.828.454h-3c-.547 0-.996-.453-.996-1 0-.2.059-.403.168-.551l4.625-6.942-4.625-6.945a.939.939 0 01-.168-.55 1 1 0 01.996-.997h3c.348 0 .649.18.828.45l4.996 7.492c.11.148.168.347.168.55zm0 0"})))}const S={collapseSidebarButton:"collapseSidebarButton_PEFL",collapseSidebarButtonIcon:"collapseSidebarButtonIcon_kv0_"};function I(e){let{onClick:t}=e;return a.createElement("button",{type:"button",title:(0,u.I)({id:"theme.docs.sidebar.collapseButtonTitle",message:"Collapse sidebar",description:"The title attribute for collapse button of doc sidebar"}),"aria-label":(0,u.I)({id:"theme.docs.sidebar.collapseButtonAriaLabel",message:"Collapse sidebar",description:"The title attribute for collapse button of doc sidebar"}),className:(0,o.Z)("button button--secondary button--outline",S.collapseSidebarButton),onClick:t},a.createElement(C,{className:S.collapseSidebarButtonIcon}))}var N=n(59689),T=n(902);const x=Symbol("EmptyContext"),Z=a.createContext(x);function B(e){let{children:t}=e;const[n,o]=(0,a.useState)(null),l=(0,a.useMemo)((()=>({expandedItem:n,setExpandedItem:o})),[n]);return a.createElement(Z.Provider,{value:l},t)}var y=n(86043),w=n(48596),L=n(39960),A=n(72389);function H(e){let{categoryLabel:t,onClick:n}=e;return a.createElement("button",{"aria-label":(0,u.I)({id:"theme.DocSidebarItem.toggleCollapsedCategoryAriaLabel",message:"Toggle the collapsible sidebar category '{label}'",description:"The ARIA label to toggle the collapsible sidebar category"},{label:t}),type:"button",className:"clean-btn menu__caret",onClick:n})}function M(e){let{item:t,onItemClick:n,activePath:l,level:i,index:s,...d}=e;const{items:m,label:u,collapsible:b,className:p,href:h}=t,{docs:{sidebar:{autoCollapseCategories:E}}}=(0,v.L)(),f=function(e){const t=(0,A.Z)();return(0,a.useMemo)((()=>e.href?e.href:!t&&e.collapsible?(0,c.Wl)(e):void 0),[e,t])}(t),g=(0,c._F)(t,l),k=(0,w.Mg)(h,l),{collapsed:C,setCollapsed:S}=(0,y.u)({initialState:()=>!!b&&(!g&&t.collapsed)}),{expandedItem:I,setExpandedItem:N}=function(){const e=(0,a.useContext)(Z);if(e===x)throw new T.i6("DocSidebarItemsExpandedStateProvider");return e}(),B=function(e){void 0===e&&(e=!C),N(e?null:s),S(e)};return function(e){let{isActive:t,collapsed:n,updateCollapsed:o}=e;const l=(0,T.D9)(t);(0,a.useEffect)((()=>{t&&!l&&n&&o(!1)}),[t,l,n,o])}({isActive:g,collapsed:C,updateCollapsed:B}),(0,a.useEffect)((()=>{b&&null!=I&&I!==s&&E&&S(!0)}),[b,I,s,S,E]),a.createElement("li",{className:(0,o.Z)(r.k.docs.docSidebarItemCategory,r.k.docs.docSidebarItemCategoryLevel(i),"menu__list-item",{"menu__list-item--collapsed":C},p)},a.createElement("div",{className:(0,o.Z)("menu__list-item-collapsible",{"menu__list-item-collapsible--active":k})},a.createElement(L.Z,(0,_.Z)({className:(0,o.Z)("menu__link",{"menu__link--sublist":b,"menu__link--sublist-caret":!h&&b,"menu__link--active":g}),onClick:b?e=>{n?.(t),h?B(!1):(e.preventDefault(),B())}:()=>{n?.(t)},"aria-current":k?"page":void 0,"aria-expanded":b?!C:void 0,href:b?f??"#":f},d),u),h&&b&&a.createElement(H,{categoryLabel:u,onClick:e=>{e.preventDefault(),B()}})),a.createElement(y.z,{lazy:!0,as:"ul",className:"menu__list",collapsed:C},a.createElement(U,{items:m,tabIndex:C?-1:0,onItemClick:n,activePath:l,level:i+1})))}var F=n(13919),P=n(39471);const W={menuExternalLink:"menuExternalLink_NmtK"};function D(e){let{item:t,onItemClick:n,activePath:l,level:i,index:s,...d}=e;const{href:m,label:u,className:b,autoAddBaseUrl:p}=t,h=(0,c._F)(t,l),E=(0,F.Z)(m);return a.createElement("li",{className:(0,o.Z)(r.k.docs.docSidebarItemLink,r.k.docs.docSidebarItemLinkLevel(i),"menu__list-item",b),key:u},a.createElement(L.Z,(0,_.Z)({className:(0,o.Z)("menu__link",!E&&W.menuExternalLink,{"menu__link--active":h}),autoAddBaseUrl:p,"aria-current":h?"page":void 0,to:m},E&&{onClick:n?()=>n(t):void 0},d),u,!E&&a.createElement(P.Z,null)))}const R={menuHtmlItem:"menuHtmlItem_M9Kj"};function V(e){let{item:t,level:n,index:l}=e;const{value:i,defaultStyle:c,className:s}=t;return a.createElement("li",{className:(0,o.Z)(r.k.docs.docSidebarItemLink,r.k.docs.docSidebarItemLinkLevel(n),c&&[R.menuHtmlItem,"menu__list-item"],s),key:l,dangerouslySetInnerHTML:{__html:i}})}function j(e){let{item:t,...n}=e;switch(t.type){case"category":return a.createElement(M,(0,_.Z)({item:t},n));case"html":return a.createElement(V,(0,_.Z)({item:t},n));default:return a.createElement(D,(0,_.Z)({item:t},n))}}function z(e){let{items:t,...n}=e;return a.createElement(B,null,t.map(((e,t)=>a.createElement(j,(0,_.Z)({key:t,item:e,index:t},n)))))}const U=(0,a.memo)(z),K={menu:"menu_SIkG",menuWithAnnouncementBar:"menuWithAnnouncementBar_GW3s"};function q(e){let{path:t,sidebar:n,className:l}=e;const i=function(){const{isActive:e}=(0,N.nT)(),[t,n]=(0,a.useState)(e);return(0,b.RF)((t=>{let{scrollY:a}=t;e&&n(0===a)}),[e]),e&&t}();return a.createElement("nav",{"aria-label":(0,u.I)({id:"theme.docs.sidebar.navAriaLabel",message:"Docs sidebar",description:"The ARIA label for the sidebar navigation"}),className:(0,o.Z)("menu thin-scrollbar",K.menu,i&&K.menuWithAnnouncementBar,l)},a.createElement("ul",{className:(0,o.Z)(r.k.docs.docSidebarMenu,"menu__list")},a.createElement(U,{items:n,activePath:t,level:1})))}const G={sidebar:"sidebar_njMd",sidebarWithHideableNavbar:"sidebarWithHideableNavbar_wUlq",sidebarHidden:"sidebarHidden_VK0M",sidebarLogo:"sidebarLogo_isFc"};function Y(e){let{path:t,sidebar:n,onCollapse:l,isHidden:r}=e;const{navbar:{hideOnScroll:i},docs:{sidebar:{hideable:c}}}=(0,v.L)();return a.createElement("div",{className:(0,o.Z)(G.sidebar,i&&G.sidebarWithHideableNavbar,r&&G.sidebarHidden)},i&&a.createElement(k.Z,{tabIndex:-1,className:G.sidebarLogo}),a.createElement(q,{path:t,sidebar:n}),c&&a.createElement(I,{onClick:l}))}const O=a.memo(Y);var X=n(13102),J=n(72961);const Q=e=>{let{sidebar:t,path:n}=e;const l=(0,J.e)();return a.createElement("ul",{className:(0,o.Z)(r.k.docs.docSidebarMenu,"menu__list")},a.createElement(U,{items:t,activePath:n,onItemClick:e=>{"category"===e.type&&e.href&&l.toggle(),"link"===e.type&&l.toggle()},level:1}))};function $(e){return a.createElement(X.Zo,{component:Q,props:e})}const ee=a.memo($);function te(e){const t=(0,g.i)(),n="desktop"===t||"ssr"===t,o="mobile"===t;return a.createElement(a.Fragment,null,n&&a.createElement(O,e),o&&a.createElement(ee,e))}const ne={expandButton:"expandButton_m80_",expandButtonIcon:"expandButtonIcon_BlDH"};function ae(e){let{toggleSidebar:t}=e;return a.createElement("div",{className:ne.expandButton,title:(0,u.I)({id:"theme.docs.sidebar.expandButtonTitle",message:"Expand sidebar",description:"The ARIA label and title attribute for expand button of doc sidebar"}),"aria-label":(0,u.I)({id:"theme.docs.sidebar.expandButtonAriaLabel",message:"Expand sidebar",description:"The ARIA label and title attribute for expand button of doc sidebar"}),tabIndex:0,role:"button",onKeyDown:t,onClick:t},a.createElement(C,{className:ne.expandButtonIcon}))}const oe={docSidebarContainer:"docSidebarContainer_b6E3",docSidebarContainerHidden:"docSidebarContainerHidden_b3ry",sidebarViewport:"sidebarViewport_Xe31"};function le(e){let{children:t}=e;const n=(0,d.V)();return a.createElement(a.Fragment,{key:n?.name??"noSidebar"},t)}function re(e){let{sidebar:t,hiddenSidebarContainer:n,setHiddenSidebarContainer:l}=e;const{pathname:i}=(0,f.TH)(),[c,s]=(0,a.useState)(!1),d=(0,a.useCallback)((()=>{c&&s(!1),l((e=>!e))}),[l,c]);return a.createElement("aside",{className:(0,o.Z)(r.k.docs.docSidebarContainer,oe.docSidebarContainer,n&&oe.docSidebarContainerHidden),onTransitionEnd:e=>{e.currentTarget.classList.contains(oe.docSidebarContainer)&&n&&s(!0)}},a.createElement(le,null,a.createElement("div",{className:(0,o.Z)(oe.sidebarViewport,c&&oe.sidebarViewportHidden)},a.createElement(te,{sidebar:t,path:i,onCollapse:d,isHidden:c}),c&&a.createElement(ae,{toggleSidebar:d}))))}const ie={docMainContainer:"docMainContainer_gTbr",docMainContainerEnhanced:"docMainContainerEnhanced_Uz_u",docItemWrapperEnhanced:"docItemWrapperEnhanced_czyv"};function ce(e){let{hiddenSidebarContainer:t,children:n}=e;const l=(0,d.V)();return a.createElement("main",{className:(0,o.Z)(ie.docMainContainer,(t||!l)&&ie.docMainContainerEnhanced)},a.createElement("div",{className:(0,o.Z)("container padding-top--md padding-bottom--lg",ie.docItemWrapper,t&&ie.docItemWrapperEnhanced)},n))}const se={docPage:"docPage__5DB",docsWrapper:"docsWrapper_BCFX"};function de(e){let{children:t}=e;const n=(0,d.V)(),[o,l]=(0,a.useState)(!1);return a.createElement(m.Z,{wrapperClassName:se.docsWrapper},a.createElement(E,null),a.createElement("div",{className:se.docPage},n&&a.createElement(re,{sidebar:n.items,hiddenSidebarContainer:o,setHiddenSidebarContainer:l}),a.createElement(ce,{hiddenSidebarContainer:o},t)))}var me=n(4972),ue=n(90197);function be(e){const{versionMetadata:t}=e;return a.createElement(a.Fragment,null,a.createElement(ue.Z,{version:t.version,tag:(0,i.os)(t.pluginId,t.version)}),a.createElement(l.d,null,t.noIndex&&a.createElement("meta",{name:"robots",content:"noindex, nofollow"})))}function pe(e){const{versionMetadata:t}=e,n=(0,c.hI)(e);if(!n)return a.createElement(me.default,null);const{docElement:i,sidebarName:m,sidebarItems:u}=n;return a.createElement(a.Fragment,null,a.createElement(be,e),a.createElement(l.FG,{className:(0,o.Z)(r.k.wrapper.docsPages,r.k.page.docsDocPage,e.versionMetadata.className)},a.createElement(s.q,{version:t},a.createElement(d.b,{name:m,items:u},a.createElement(de,null,i)))))}},4972:(e,t,n)=>{n.r(t),n.d(t,{default:()=>i});var a=n(67294),o=n(95999),l=n(10833),r=n(31735);function i(){return a.createElement(a.Fragment,null,a.createElement(l.d,{title:(0,o.I)({id:"theme.NotFound.title",message:"Page Not Found"})}),a.createElement(r.Z,null,a.createElement("main",{className:"container margin-vert--xl"},a.createElement("div",{className:"row"},a.createElement("div",{className:"col col--6 col--offset-3"},a.createElement("h1",{className:"hero__title"},a.createElement(o.Z,{id:"theme.NotFound.title",description:"The title of the 404 page"},"Page Not Found")),a.createElement("p",null,a.createElement(o.Z,{id:"theme.NotFound.p1",description:"The first paragraph of the 404 page"},"We could not find what you were looking for.")),a.createElement("p",null,a.createElement(o.Z,{id:"theme.NotFound.p2",description:"The 2nd paragraph of the 404 page"},"Please contact the owner of the site that linked you to the original URL and let them know their link is broken.")))))))}},74477:(e,t,n)=>{n.d(t,{E:()=>i,q:()=>r});var a=n(67294),o=n(902);const l=a.createContext(null);function r(e){let{children:t,version:n}=e;return a.createElement(l.Provider,{value:n},t)}function i(){const e=(0,a.useContext)(l);if(null===e)throw new o.i6("DocsVersionProvider");return e}}}]);
--------------------------------------------------------------------------------
/assets/js/b728f6fe.bba33834.js:
--------------------------------------------------------------------------------
1 | "use strict";(self.webpackChunkjjbook=self.webpackChunkjjbook||[]).push([[5211],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>d});var n=r(67294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},c=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},k=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,l=e.originalType,p=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),m=s(r),k=a,d=m["".concat(p,".").concat(k)]||m[k]||u[k]||l;return r?n.createElement(d,o(o({ref:t},c),{},{components:r})):n.createElement(d,o({ref:t},c))}));function d(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=r.length,o=new Array(l);o[0]=k;var i={};for(var p in t)hasOwnProperty.call(t,p)&&(i[p]=t[p]);i.originalType=e,i[m]="string"==typeof e?e:a,o[1]=i;for(var s=2;s{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>o,default:()=>u,frontMatter:()=>l,metadata:()=>i,toc:()=>s});var n=r(87462),a=(r(67294),r(3905));const l={sidebar_label:"\u6d4f\u89c8\u5668\uff1a\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",sidebar_position:2},o="\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",i={unversionedId:"book1/browser-repain-reflow",id:"book1/browser-repain-reflow",title:"\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",description:"\u76f8\u5173\u95ee\u9898",source:"@site/docs/book1/browser-repain-reflow.md",sourceDirName:"book1",slug:"/book1/browser-repain-reflow",permalink:"/awesome-interview/book1/browser-repain-reflow",draft:!1,tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_label:"\u6d4f\u89c8\u5668\uff1a\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"\u6d4f\u89c8\u5668\uff1a\u6d4f\u89c8\u5668\u8de8\u57df",permalink:"/awesome-interview/book1/browser-cross-origin"},next:{title:"\u5de5\u7a0b\u5316\uff1awebpack \u5de5\u4f5c\u6d41\u7a0b",permalink:"/awesome-interview/book1/engineer-webpack-workflow"}},p={},s=[{value:"\u76f8\u5173\u95ee\u9898",id:"\u76f8\u5173\u95ee\u9898",level:2},{value:"\u56de\u7b54\u5173\u952e\u70b9",id:"\u56de\u7b54\u5173\u952e\u70b9",level:2},{value:"\u77e5\u8bc6\u70b9\u6df1\u5165",id:"\u77e5\u8bc6\u70b9\u6df1\u5165",level:2},{value:"1. \u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8",id:"1-\u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8",level:3},{value:"\u5f15\u8d77\u91cd\u6392/\u91cd\u7ed8\u7684\u5e38\u89c1\u64cd\u4f5c",id:"\u5f15\u8d77\u91cd\u6392\u91cd\u7ed8\u7684\u5e38\u89c1\u64cd\u4f5c",level:4},{value:"2. \u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8",id:"2-\u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8",level:3},{value:"\u610f\u4e49",id:"\u610f\u4e49",level:4},{value:"\u89e3\u51b3\u65b9\u6848",id:"\u89e3\u51b3\u65b9\u6848",level:4},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",level:2}],c={toc:s},m="wrapper";function u(e){let{components:t,...r}=e;return(0,a.kt)(m,(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8"},"\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8"),(0,a.kt)("h2",{id:"\u76f8\u5173\u95ee\u9898"},"\u76f8\u5173\u95ee\u9898"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"\u5982\u4f55\u63d0\u5347\u9875\u9762\u6e32\u67d3\u6027\u80fd"),(0,a.kt)("li",{parentName:"ul"},"\u5982\u4f55\u51cf\u5c11\u9875\u9762\u91cd\u6392\u91cd\u7ed8"),(0,a.kt)("li",{parentName:"ul"},"\u54ea\u4e9b\u884c\u4e3a\u4f1a\u5f15\u8d77\u91cd\u6392/\u91cd\u7ed8")),(0,a.kt)("h2",{id:"\u56de\u7b54\u5173\u952e\u70b9"},"\u56de\u7b54\u5173\u952e\u70b9"),(0,a.kt)("p",null,(0,a.kt)("inlineCode",{parentName:"p"},"\u6e32\u67d3\u6027\u80fd")," ",(0,a.kt)("inlineCode",{parentName:"p"},"Layout")," ",(0,a.kt)("inlineCode",{parentName:"p"},"Paint")),(0,a.kt)("p",null,"\u6d4f\u89c8\u5668\u6e32\u67d3\u5927\u81f4\u5206\u4e3a\u56db\u4e2a\u9636\u6bb5\uff0c\u5176\u4e2d\u5728\u89e3\u6790 HTML \u540e\uff0c\u4f1a\u4f9d\u6b21\u8fdb\u5165 Layout \u548c Paint \u9636\u6bb5\u3002",(0,a.kt)("strong",{parentName:"p"},"\u6837\u5f0f\u6216\u8282\u70b9\u7684\u66f4\u6539\uff0c\u4ee5\u53ca\u5bf9\u5e03\u5c40\u4fe1\u606f\u7684\u8bbf\u95ee\u7b49"),"\uff0c\u90fd\u6709\u53ef\u80fd\u5bfc\u81f4\u91cd\u6392\u548c\u91cd\u7ed8\u3002\u800c\u91cd\u6392\u548c\u91cd\u7ed8\u7684\u8fc7\u7a0b\u5728",(0,a.kt)("strong",{parentName:"p"},"\u4e3b\u7ebf\u7a0b"),"\u4e2d\u8fdb\u884c\uff0c\u8fd9\u610f\u5473\u7740\u4e0d\u5408\u7406\u7684\u91cd\u6392\u91cd\u7ed8\u4f1a\u5bfc\u81f4",(0,a.kt)("strong",{parentName:"p"},"\u6e32\u67d3\u5361\u987f\uff0c\u7528\u6237\u4ea4\u4e92\u6ede\u540e"),"\u7b49\u6027\u80fd\u95ee\u9898\u3002"),(0,a.kt)("h2",{id:"\u77e5\u8bc6\u70b9\u6df1\u5165"},"\u77e5\u8bc6\u70b9\u6df1\u5165"),(0,a.kt)("h3",{id:"1-\u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8"},"1. \u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8"),(0,a.kt)("p",null,(0,a.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/126033732-d5002255-1c88-4dee-9371-da166aacdca9.png",alt:"image"})),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},"Parse HTML\uff1a\u76f8\u5173\u5f15\u64ce\u5206\u522b\u89e3\u6790\u6587\u6863\u548c\u6837\u5f0f\u8868\u4ee5\u53ca\u811a\u672c\uff0c\u751f\u6210 DOM \u548c CSSOM \uff0c\u6700\u7ec8\u5408\u6210\u4e3a Render \u6811\u3002"),(0,a.kt)("li",{parentName:"ol"},"Layout\uff1a\u6d4f\u89c8\u5668\u901a\u8fc7 Render \u6811\u4e2d\u7684\u4fe1\u606f\uff0c\u4ee5\u9012\u5f52\u7684\u5f62\u5f0f\u8ba1\u7b97\u51fa\u6bcf\u4e2a\u8282\u70b9\u7684\u5c3a\u5bf8\u5927\u5c0f\u548c\u5728\u9875\u9762\u4e2d\u7684\u5177\u4f53\u4f4d\u7f6e\u3002"),(0,a.kt)("li",{parentName:"ol"},"Paint\uff1a\u6d4f\u89c8\u5668\u5c06 Render \u6811\u4e2d\u7684\u8282\u70b9\u8f6c\u6362\u6210\u5728\u5c4f\u5e55\u4e0a\u7ed8\u5236\u5b9e\u9645\u50cf\u7d20\u7684\u6307\u4ee4\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u53d1\u751f\u5728\u591a\u4e2a\u56fe\u5c42\u4e0a\u3002"),(0,a.kt)("li",{parentName:"ol"},"Composite\uff1a\u6d4f\u89c8\u5668\u5c06\u6240\u6709\u5c42\u6309\u7167\u4e00\u5b9a\u987a\u5e8f\u5408\u5e76\u4e3a\u4e00\u4e2a\u56fe\u5c42\u5e76\u7ed8\u5236\u5728\u5c4f\u5e55\u4e0a\u3002")),(0,a.kt)("p",null,"\u56fe\u4e2d\u6240\u793a\u6b65\u9aa4\u4e3a\u6d4f\u89c8\u5668\u6e32\u67d3\u7684\u5173\u952e\u8def\u5f84\u3002\u6d4f\u89c8\u5668\u4ece\u83b7\u53d6\u6587\u6863\u3001\u6837\u5f0f\u3001\u811a\u672c\u7b49\u5185\u5bb9\uff0c\u5230\u6700\u7ec8\u6e32\u67d3\u7ed3\u679c\u5230\u5c4f\u5e55\u4e0a\uff0c\u901a\u5e38\u9700\u8981\u7ecf\u8fc7\u5982\u56fe\u6240\u793a\u7684\u6b65\u9aa4\u3002\u800c DOM \u6216 CSSOM \u88ab\u4fee\u6539\uff0c\u4f1a\u5bfc\u81f4\u6d4f\u89c8\u5668\u91cd\u590d\u6267\u884c\u56fe\u4e2d\u7684\u6b65\u9aa4\u3002\u91cd\u6392\u548c\u91cd\u7ed8\uff0c\u672c\u8d28\u4e0a\u6307\u7684\u5c31\u662f\u89e6\u53d1 Layout \u548c Paint \u7684\u8fc7\u7a0b\uff0c\u4e14\u91cd\u6392\u5fc5\u5b9a\u5bfc\u81f4\u91cd\u7ed8\u3002"),(0,a.kt)("h4",{id:"\u5f15\u8d77\u91cd\u6392\u91cd\u7ed8\u7684\u5e38\u89c1\u64cd\u4f5c"},"\u5f15\u8d77\u91cd\u6392/\u91cd\u7ed8\u7684\u5e38\u89c1\u64cd\u4f5c"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},"\u5916\u89c2\u6709\u53d8\u5316\u65f6\uff0c\u4f1a\u5bfc\u81f4",(0,a.kt)("strong",{parentName:"li"},"\u91cd\u7ed8"),"\u3002\u76f8\u5173\u7684\u6837\u5f0f\u5c5e\u6027\u5982 ",(0,a.kt)("inlineCode",{parentName:"li"},"color")," ",(0,a.kt)("inlineCode",{parentName:"li"},"opacity")," \u7b49\u3002"),(0,a.kt)("li",{parentName:"ol"},"\u5e03\u5c40\u7ed3\u6784\u6216\u8282\u70b9\u5185\u5bb9\u53d8\u5316\u65f6\uff0c\u4f1a\u5bfc\u81f4",(0,a.kt)("strong",{parentName:"li"},"\u91cd\u6392"),"\u3002\u76f8\u5173\u7684\u6837\u5f0f\u5c5e\u6027\u5982 ",(0,a.kt)("inlineCode",{parentName:"li"},"height")," ",(0,a.kt)("inlineCode",{parentName:"li"},"float")," ",(0,a.kt)("inlineCode",{parentName:"li"},"position")," \u7b49\u3002",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},"\u76d2\u5b50\u5c3a\u5bf8\u548c\u7c7b\u578b\u3002"),(0,a.kt)("li",{parentName:"ul"},"\u5b9a\u4f4d\u65b9\u6848\uff08\u6b63\u5e38\u6d41\u3001\u6d6e\u52a8\u548c\u7edd\u5bf9\u5b9a\u4f4d\uff09\u3002"),(0,a.kt)("li",{parentName:"ul"},"\u6587\u6863\u6811\u4e2d\u5143\u7d20\u4e4b\u95f4\u7684\u5173\u7cfb\u3002"),(0,a.kt)("li",{parentName:"ul"},"\u5916\u90e8\u4fe1\u606f\uff08\u5982\u89c6\u53e3\u5927\u5c0f\u7b49\uff09\u3002"))),(0,a.kt)("li",{parentName:"ol"},"\u83b7\u53d6\u5e03\u5c40\u4fe1\u606f\u65f6\uff0c\u4f1a\u5bfc\u81f4",(0,a.kt)("strong",{parentName:"li"},"\u91cd\u6392"),"\u3002\u76f8\u5173\u7684\u65b9\u6cd5\u5c5e\u6027\u5982 ",(0,a.kt)("inlineCode",{parentName:"li"},"offsetTop")," ",(0,a.kt)("inlineCode",{parentName:"li"},"getComputedStyle")," \u7b49\u3002")),(0,a.kt)("h3",{id:"2-\u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8"},"2. \u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8"),(0,a.kt)("p",null,(0,a.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/126033739-3e689aab-fcd8-4928-9e6d-6a047ab2a8c9.png",alt:"image"})),(0,a.kt)("h4",{id:"\u610f\u4e49"},"\u610f\u4e49"),(0,a.kt)("p",null,"\u5927\u591a\u6570\u663e\u793a\u5668\u7684\u5237\u65b0\u7387\u662f 60FPS\uff08frames per second\uff09\u3002\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6d4f\u89c8\u5668\u9700\u8981\u5728 1/60 \u79d2\u5185\u5b8c\u6210\u6e32\u67d3\u9636\u6bb5\u5e76\u4ea4\u4ed8\u4e00\u5e27\u3002\u8fd9\u6837\u7528\u6237\u5c31\u4f1a\u770b\u5230\u4e00\u4e2a\u4ea4\u4e92\u6d41\u7545\u7684\u9875\u9762\u3002"),(0,a.kt)("p",null,"\u5728\u4ea4\u4e92\u9636\u6bb5\uff0c\u9875\u9762\u66f4\u65b0\uff08\u4e00\u822c\u662f\u901a\u8fc7\u6267\u884c JavaScript \u6765\u89e6\u53d1\uff09\u901a\u5e38\u4f1a\u89e6\u53d1\u91cd\u6392\u548c\u91cd\u7ed8\u3002\u4e3a\u4e86\u63d0\u5347\u6d4f\u89c8\u5668\u6e32\u67d3\u6548\u7387\uff0c\u5e94\u5f53\u5c3d\u53ef\u80fd\u51cf\u5c11\u91cd\u7ed8\u91cd\u6392\uff08\u8df3\u8fc7 Layout/Paint \u6b65\u9aa4\uff09\uff0c\u4ece\u800c\u964d\u4f4e\u6d4f\u89c8\u5668\u6e32\u67d3\u8017\u8d39\u7684\u65f6\u95f4\uff0c\u5c06\u5185\u5bb9\u5c3d\u5feb\u6e32\u67d3\u5230\u5c4f\u5e55\u4e0a\u3002"),(0,a.kt)("h4",{id:"\u89e3\u51b3\u65b9\u6848"},"\u89e3\u51b3\u65b9\u6848"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},"\u5bf9 DOM \u8fdb\u884c\u6279\u91cf\u5199\u5165\u548c\u8bfb\u53d6\uff08\u901a\u8fc7\u865a\u62df DOM \u6216\u8005 DocumentFragment \u5b9e\u73b0\uff09\u3002"),(0,a.kt)("li",{parentName:"ol"},"\u907f\u514d\u5bf9\u6837\u5f0f\u9891\u7e41\u64cd\u4f5c\uff0c\u4e86\u89e3\u5e38\u7528\u6837\u5f0f\u5c5e\u6027\u89e6\u53d1 Layout / Paint / Composite \u7684",(0,a.kt)("a",{parentName:"li",href:"https://csstriggers.com/"},"\u673a\u5236"),"\uff0c\u5408\u7406\u4f7f\u7528\u6837\u5f0f\u3002"),(0,a.kt)("li",{parentName:"ol"},"\u5408\u7406\u5229\u7528\u7279\u6b8a\u6837\u5f0f\u5c5e\u6027\uff08\u5982 transform: translateZ(0) \u6216\u8005 will-change\uff09\uff0c\u5c06\u6e32\u67d3\u5c42\u63d0\u5347\u4e3a\u5408\u6210\u5c42\uff0c\u5f00\u542f GPU \u52a0\u901f\uff0c\u63d0\u9ad8\u9875\u9762\u6027\u80fd\u3002"),(0,a.kt)("li",{parentName:"ol"},"\u4f7f\u7528\u53d8\u91cf\u5bf9\u5e03\u5c40\u4fe1\u606f\uff08\u5982 clientTop\uff09\u8fdb\u884c\u7f13\u5b58\uff0c\u907f\u514d\u56e0\u9891\u7e41\u8bfb\u53d6\u5e03\u5c40\u4fe1\u606f\u800c\u89e6\u53d1\u91cd\u6392\u548c\u91cd\u7ed8\u3002")),(0,a.kt)("p",null,"\u53e6\u5916\uff0c\u53ef\u4ee5\u501f\u52a9 DevTools Performance \u9762\u677f\u6765\u67e5\u770b\u4ea7\u751f\u91cd\u6392\u91cd\u7ed8\u4efb\u52a1\u5360\u7528\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u548c\u8c03\u7528\u4ee3\u7801\u3002"),(0,a.kt)("h2",{id:"\u53c2\u8003\u8d44\u6599"},"\u53c2\u8003\u8d44\u6599"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction?hl=zh-cn"},"\u6e32\u67d3\u6811\u6784\u5efa\u3001\u5e03\u5c40\u53ca\u7ed8\u5236")),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing"},"\u907f\u514d\u5927\u578b\u3001\u590d\u6742\u7684\u5e03\u5c40\u548c\u5e03\u5c40\u6296\u52a8")),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://csstriggers.com/"},"CSS \u5c5e\u6027\u89e6\u53d1\u5e03\u5c40\u3001\u7ed8\u5236\u53ca\u5408\u6210\u7684\u6570\u636e")),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",{parentName:"li",href:"https://gist.github.com/paulirish/5d52fb081b3570c81e3a"},"What forces layout / reflow"))))}u.isMDXComponent=!0}}]);
--------------------------------------------------------------------------------
/assets/js/f4f9ee34.40b1280a.js:
--------------------------------------------------------------------------------
1 | "use strict";(self.webpackChunkjjbook=self.webpackChunkjjbook||[]).push([[4109],{3905:(e,t,r)=>{r.d(t,{Zo:()=>m,kt:()=>k});var o=r(67294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function a(e){for(var t=1;t=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(o=0;o=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var i=o.createContext({}),s=function(e){var t=o.useContext(i),r=t;return e&&(r="function"==typeof e?e(t):a(a({},t),e)),r},m=function(e){var t=s(e.components);return o.createElement(i.Provider,{value:t},e.children)},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return o.createElement(o.Fragment,{},t)}},d=o.forwardRef((function(e,t){var r=e.components,n=e.mdxType,l=e.originalType,i=e.parentName,m=p(e,["components","mdxType","originalType","parentName"]),c=s(r),d=n,k=c["".concat(i,".").concat(d)]||c[d]||u[d]||l;return r?o.createElement(k,a(a({ref:t},m),{},{components:r})):o.createElement(k,a({ref:t},m))}));function k(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var l=r.length,a=new Array(l);a[0]=d;var p={};for(var i in t)hasOwnProperty.call(t,i)&&(p[i]=t[i]);p.originalType=e,p[c]="string"==typeof e?e:n,a[1]=p;for(var s=2;s{r.r(t),r.d(t,{assets:()=>i,contentTitle:()=>a,default:()=>u,frontMatter:()=>l,metadata:()=>p,toc:()=>s});var o=r(87462),n=(r(67294),r(3905));const l={sidebar_label:"\u6d4f\u89c8\u5668\uff1a\u5982\u4f55\u5b9a\u4f4d\u5185\u5b58\u6cc4\u9732",sidebar_position:2},a="\u5982\u4f55\u5b9a\u4f4d\u5185\u5b58\u6cc4\u9732",p={unversionedId:"book3/browser-memory-leaks",id:"book3/browser-memory-leaks",title:"\u5982\u4f55\u5b9a\u4f4d\u5185\u5b58\u6cc4\u9732",description:"\u76f8\u5173\u95ee\u9898",source:"@site/docs/book3/browser-memory-leaks.md",sourceDirName:"book3",slug:"/book3/browser-memory-leaks",permalink:"/awesome-interview/book3/browser-memory-leaks",draft:!1,tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_label:"\u6d4f\u89c8\u5668\uff1a\u5982\u4f55\u5b9a\u4f4d\u5185\u5b58\u6cc4\u9732",sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"\u6d4f\u89c8\u5668\uff1a\u6d4f\u89c8\u5668\u4e8b\u4ef6\u5faa\u73af",permalink:"/awesome-interview/book3/browser-event-loop"},next:{title:"\u5de5\u7a0b\u5316\uff1a\u8c08\u4e0b webpack loader \u7684\u673a\u5236",permalink:"/awesome-interview/book3/engineer-webpack-loader"}},i={},s=[{value:"\u76f8\u5173\u95ee\u9898",id:"\u76f8\u5173\u95ee\u9898",level:2},{value:"\u56de\u7b54\u5173\u952e\u70b9",id:"\u56de\u7b54\u5173\u952e\u70b9",level:2},{value:"\u77e5\u8bc6\u70b9\u6df1\u5165",id:"\u77e5\u8bc6\u70b9\u6df1\u5165",level:2},{value:"1. \u6392\u67e5\u5185\u5b58\u6cc4\u6f0f\u5e38\u89c1\u95ee\u9898",id:"1-\u6392\u67e5\u5185\u5b58\u6cc4\u6f0f\u5e38\u89c1\u95ee\u9898",level:3},{value:"2. \u4f7f\u7528 Chrome DevTools \u5b9a\u4f4d\u5185\u5b58\u6cc4\u6f0f",id:"2-\u4f7f\u7528-chrome-devtools-\u5b9a\u4f4d\u5185\u5b58\u6cc4\u6f0f",level:3},{value:"Performance",id:"performance",level:4},{value:"Memory",id:"memory",level:4},{value:"3. Node.js \u4e2d\u7684\u5185\u5b58\u6cc4\u6f0f\u5b9a\u4f4d",id:"3-nodejs-\u4e2d\u7684\u5185\u5b58\u6cc4\u6f0f\u5b9a\u4f4d",level:3},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",level:2}],m={toc:s},c="wrapper";function u(e){let{components:t,...r}=e;return(0,n.kt)(c,(0,o.Z)({},m,r,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("h1",{id:"\u5982\u4f55\u5b9a\u4f4d\u5185\u5b58\u6cc4\u9732"},"\u5982\u4f55\u5b9a\u4f4d\u5185\u5b58\u6cc4\u9732"),(0,n.kt)("h2",{id:"\u76f8\u5173\u95ee\u9898"},"\u76f8\u5173\u95ee\u9898"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},"\u5783\u573e\u56de\u6536\u673a\u5236")),(0,n.kt)("h2",{id:"\u56de\u7b54\u5173\u952e\u70b9"},"\u56de\u7b54\u5173\u952e\u70b9"),(0,n.kt)("p",null,(0,n.kt)("inlineCode",{parentName:"p"},"\u5783\u573e\u56de\u6536")," ",(0,n.kt)("inlineCode",{parentName:"p"},"DevTools")),(0,n.kt)("p",null,"\u5185\u5b58\u6cc4\u6f0f\u662f\u6307\u4e0d\u518d\u4f7f\u7528\u7684\u5185\u5b58\uff0c\u6ca1\u6709\u88ab\u5783\u573e\u56de\u6536\u673a\u5236\u56de\u6536\u3002\u5f53\u5185\u5b58\u6cc4\u6f0f\u5f88\u5927\u6216\u8db3\u591f\u9891\u7e41\u65f6\uff0c\u7528\u6237\u4f1a\u6709\u6240\u611f\u77e5\uff1a\u8f7b\u5219\u5f71\u54cd\u5e94\u7528\u6027\u80fd\uff0c\u8868\u73b0\u4e3a\u8fdf\u7f13\u5361\u987f\uff1b\u91cd\u5219\u5bfc\u81f4\u5e94\u7528\u5d29\u6e83\uff0c\u8868\u73b0\u4e3a\u65e0\u6cd5\u6b63\u5e38\u4f7f\u7528\u3002\u4e3a\u4e86\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u5e26\u6765\u7684\u4e0d\u826f\u5f71\u54cd\uff0c\u9700\u8981\u5bf9\u5783\u573e\u56de\u6536\u673a\u5236\u8fdb\u884c\u4e86\u89e3\uff0c\u638c\u63e1\u5185\u5b58\u6cc4\u6f0f\u5206\u6790\u65b9\u6cd5\uff0c\u5b8c\u5584\u7ebf\u4e0a\u76f8\u5173\u76d1\u63a7\u63aa\u65bd\u3002"),(0,n.kt)("p",null,"\u5185\u5b58\u6cc4\u6f0f\u5b9a\u4f4d\u548c\u5206\u6790\u4e00\u822c\u9700\u8981\u8f85\u52a9\u5de5\u5177\uff0c\u6bd4\u5982 Chrome DevTools\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7 DevTools \u8bb0\u5f55\u9875\u9762\u6d3b\u52a8\u6982\u51b5\uff0c\u751f\u6210\u53ef\u89c6\u5316\u5206\u6790\u7ed3\u679c\uff0c\u4ece\u65f6\u95f4\u8f74\u4e2d\u76f4\u89c2\u4e86\u89e3\u5185\u5b58\u6cc4\u6f0f\u60c5\u51b5\uff1b\u5229\u7528 DevTools \u83b7\u53d6\u82e5\u5e72\u6b21\u5185\u5b58\u5feb\u7167\uff0c\u68c0\u67e5\u5185\u5b58\u5806\u6808\u53d8\u5316\uff1b\u4ee5\u53ca\u4f7f\u7528 Chrome \u4efb\u52a1\u7ba1\u7406\u5668\uff0c\u5b9e\u65f6\u76d1\u63a7\u5185\u5b58\u7684\u4f7f\u7528\u60c5\u51b5\u3002"),(0,n.kt)("h2",{id:"\u77e5\u8bc6\u70b9\u6df1\u5165"},"\u77e5\u8bc6\u70b9\u6df1\u5165"),(0,n.kt)("h3",{id:"1-\u6392\u67e5\u5185\u5b58\u6cc4\u6f0f\u5e38\u89c1\u95ee\u9898"},"1. \u6392\u67e5\u5185\u5b58\u6cc4\u6f0f\u5e38\u89c1\u95ee\u9898"),(0,n.kt)("p",null,"\u5728 JavaScript \u4e2d\uff0c\u5f53\u4e00\u4e9b\u4e0d\u518d\u9700\u8981\u7684\u6570\u636e\u4ecd\u7136\u53ef\u8fbe\u65f6\uff0cV8 \u4f1a\u8ba4\u4e3a\u8fd9\u4e9b\u6570\u636e\u4ecd\u5728\u88ab\u4f7f\u7528\uff0c\u4e0d\u4f1a\u91ca\u653e\u5185\u5b58\u3002\u4e3a\u4e86\u8c03\u8bd5\u5185\u5b58\u6cc4\u6f0f\uff0c\u6211\u4eec\u9700\u8981\u627e\u5230\u88ab\u9519\u8bef\u4fdd\u7559\u7684\u6570\u636e\uff0c\u5e76\u786e\u4fdd V8 \u80fd\u591f\u5c06\u5176\u6e05\u7406\u6389\u3002"),(0,n.kt)("p",null,"\u4ee3\u7801\u91cf\u8f83\u5c0f\u65f6\uff0c\u5f00\u53d1\u8005\u901a\u5e38\u53ef\u4ee5\u57fa\u4e8e\u4ee5\u4e0b\u57fa\u672c\u539f\u5219\u8fdb\u884c\u5feb\u901f\u81ea\u67e5\uff1a"),(0,n.kt)("ol",null,(0,n.kt)("li",{parentName:"ol"},"\u662f\u5426\u6ee5\u7528\u5168\u5c40\u53d8\u91cf\uff0c\u6ca1\u6709\u624b\u52a8\u56de\u6536\u3002"),(0,n.kt)("li",{parentName:"ol"},"\u662f\u5426\u6ca1\u6709\u6b63\u786e\u9500\u6bc1\u5b9a\u65f6\u5668\u3001\u95ed\u5305\u3002"),(0,n.kt)("li",{parentName:"ol"},"\u662f\u5426\u6ca1\u6709\u6b63\u786e\u76d1\u542c\u4e8b\u4ef6\u548c\u9500\u6bc1\u4e8b\u4ef6\u3002")),(0,n.kt)("p",null,"\u9664\u6b64\u4e4b\u5916\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u501f\u52a9\u5916\u90e8\u5de5\u5177\u8fdb\u884c\u5185\u5b58\u6cc4\u6f0f\u6392\u67e5\u3002"),(0,n.kt)("h3",{id:"2-\u4f7f\u7528-chrome-devtools-\u5b9a\u4f4d\u5185\u5b58\u6cc4\u6f0f"},"2. \u4f7f\u7528 Chrome DevTools \u5b9a\u4f4d\u5185\u5b58\u6cc4\u6f0f"),(0,n.kt)("h4",{id:"performance"},"Performance"),(0,n.kt)("p",null,(0,n.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/129483290-b6fa5f92-2509-49af-9866-e1b08502fe51.png",alt:"image"})),(0,n.kt)("p",null,"\u6253\u5f00\u51c6\u5907\u5206\u6790\u7684\u9875\u9762\u548c DevTools \u7684 Performance \u9762\u677f\uff0c\u52fe\u9009 Memory \u5e76\u5f00\u59cb\u5f55\u5236\uff0c\u5728\u6a21\u62df\u7528\u6237\u64cd\u4f5c\u4e00\u6bb5\u65f6\u95f4\u540e\u7ed3\u675f\u5f55\u5236\uff0cDevTools \u4f1a\u5c06\u8fd9\u6bb5\u65f6\u95f4\u5185\u7684\u9875\u9762\u884c\u4e3a\u6d3b\u52a8\u8fdb\u884c\u8bb0\u5f55\u548c\u5206\u6790\u3002"),(0,n.kt)("p",null,"\u901a\u8fc7\u751f\u6210\u7684\u7ed3\u679c\u53ef\u4ee5\u76f4\u89c2\u67e5\u770b\u5230\u5185\u5b58\u65f6\u95f4\u7ebf\uff0c\u4e86\u89e3\u5185\u5b58\u968f\u65f6\u95f4\u7684\u5360\u7528\u53d8\u5316\uff0c\u5982\u679c\u5185\u5b58\u5360\u7528\u66f2\u7ebf\u6210\u9636\u68af\u72b6\u4e00\u76f4\u4e0a\u5347\uff0c\u5219\u53ef\u80fd\u5b58\u5728\u5185\u5b58\u6cc4\u6f0f\u3002\u6309\u9700\u9009\u53d6\u65f6\u95f4\u7ebf\u4e2d\u7684\u533a\u57df\u7247\u6bb5\uff0c\u68c0\u67e5\u5bf9\u5e94\u65f6\u95f4\u6bb5\u5185\u7684\u6d3b\u52a8\u7c7b\u578b\u548c\u65f6\u95f4\u5360\u7528\uff0c\u4f5c\u4e3a\u6392\u67e5\u548c\u5b9a\u4f4d\u5185\u5b58\u6cc4\u6f0f\u7684\u8f85\u52a9\u529e\u6cd5\u3002"),(0,n.kt)("h4",{id:"memory"},"Memory"),(0,n.kt)("p",null,(0,n.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/130357605-39e4ffb0-f679-4331-91c0-f9958e70e8a9.png",alt:"image"})),(0,n.kt)("p",null,"\u6253\u5f00\u51c6\u5907\u5206\u6790\u7684\u9875\u9762\u548c DevTools \u7684 Memory \u9762\u677f\uff0c\u6309\u9700\u751f\u6210\u5feb\u7167\u3002\u6bcf\u4e2a\u5feb\u7167\u7684\u5185\u5bb9\u662f\u5feb\u7167\u65f6\u523b\uff0c\u8fdb\u884c\u4e00\u6b21\u5783\u573e\u56de\u6536\u540e\uff0c\u5e94\u7528\u4e2d\u6240\u6709\u53ef\u8fbe\u7684\u5bf9\u8c61\u3002"),(0,n.kt)("p",null,"\u5f53\u5f00\u53d1\u8005\u660e\u786e\u77e5\u9053\u4e0e\u5185\u5b58\u6cc4\u6f0f\u5173\u8054\u7684\u7528\u6237\u4ea4\u4e92\u6b65\u9aa4\u65f6\uff0c\u53ef\u4ee5\u751f\u6210\u591a\u6b21\u5185\u5b58\u5feb\u7167\u8fdb\u884c\u5bf9\u6bd4\uff0c\u6392\u67e5\u51fa\u6cc4\u6f0f\u7684\u5bf9\u8c61\uff1a\u5728\u505a\u7528\u6237\u4ea4\u4e92\u64cd\u4f5c\u4e4b\u524d\uff0c\u8fdb\u884c\u4e00\u6b21\u6b63\u5e38\u5185\u5b58\u5806\u6808\u4fe1\u606f\u7684\u5feb\u7167\uff1b\u5728\u505a\u7528\u6237\u4ea4\u4e92\u64cd\u4f5c\u4e2d\u6216\u64cd\u4f5c\u7ed3\u675f\u65f6\uff0c\u8fdb\u884c\u5185\u5b58\u5feb\u7167\u3002\u4f7f\u7528 Comparison \u89c6\u56fe\u6216\u4f7f\u7528 filter \u6309\u9700\u67e5\u770b\u5feb\u7167\u4e4b\u95f4\u7684\u5dee\u5f02\u3002"),(0,n.kt)("p",null,"\u4e0a\u9762\u7684\u56fe\u4e2d\u4f7f\u7528 filter \u68c0\u67e5\u5feb\u7167 2 \u548c\u5feb\u7167 3 \u7684\u5dee\u5f02\uff0c\u901a\u8fc7\u7ed3\u679c\u53ef\u77e5\u5728\u4e24\u4e2a\u5feb\u7167\u4e4b\u95f4\u6301\u7eed\u88ab\u5206\u914d clickCallback \u95ed\u5305\u3002\u901a\u8fc7\u70b9\u51fb\u6587\u4ef6\u8def\u5f84\u53ef\u4ee5\u5b9a\u4f4d\u5230\u5185\u5b58\u6cc4\u6f0f\u7684\u4ee3\u7801\u3002"),(0,n.kt)("p",null,(0,n.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/130357708-28497c8f-93f8-4afd-a53f-9506eaa3de9c.png",alt:"image"})),(0,n.kt)("h3",{id:"3-nodejs-\u4e2d\u7684\u5185\u5b58\u6cc4\u6f0f\u5b9a\u4f4d"},"3. Node.js \u4e2d\u7684\u5185\u5b58\u6cc4\u6f0f\u5b9a\u4f4d"),(0,n.kt)("p",null,"\u5982\u679c\u9700\u8981\u5b9a\u4f4d Node.js \u4e2d\u7684\u5185\u5b58\u6cc4\u6f0f\uff0c\u542f\u52a8 Node.js \u65f6\u5e26\u4e0a --inspect \u53c2\u6570\uff0c\u4ee5\u4fbf\u5229\u7528 Chrome DevTools \u5de5\u5177\u751f\u6210 Memory \u5feb\u7167\u6570\u636e\u3002\u5982\u56fe\u6240\u793a\uff0c\u542f\u52a8 Node.js \u670d\u52a1\u540e\uff0c\u6253\u5f00 Chrome DevTools\uff0c\u4f1a\u6709 Node \u6807\u8bc6\uff0c\u70b9\u51fb\u53ef\u4ee5\u6253\u5f00 Node \u4e13\u7528 DevTools\u3002"),(0,n.kt)("p",null,(0,n.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/130330062-c37a1085-1464-4cc9-8aa0-2f65decead03.png",alt:"image"})),(0,n.kt)("p",null,"\u9664\u6b64\u4e4b\u5916\uff0c\u4e5f\u53ef\u4ee5\u501f\u52a9\u7b2c\u4e09\u65b9\u5305 heapdump \u751f\u6210\u5feb\u7167\u6587\u4ef6\uff0c\u5bfc\u5165\u81f3 Chrome DevTools \u4e2d\u7684 Memory \u8fdb\u884c\u5feb\u7167\u5bf9\u6bd4\u3002"),(0,n.kt)("p",null,"\u542f\u52a8 Node.js \u65f6\u5e26\u4e0a --expose-gc \u53c2\u6570\u4ee5\u4fbf\u8c03\u7528 ",(0,n.kt)("inlineCode",{parentName:"p"},"global.gc()")," \u65b9\u6cd5\u89e6\u53d1\u5783\u573e\u56de\u6536\u3002\u501f\u52a9 ",(0,n.kt)("inlineCode",{parentName:"p"},"process.memoryUsage().heapUsed")," \u68c0\u67e5\u5185\u5b58\u5927\u5c0f\uff0c\u4f5c\u4e3a\u5185\u5b58\u6cc4\u6f0f\u7684\u8f85\u52a9\u5224\u65ad\u3002"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},'const heapdump = require("heapdump");\n\nconst capture = function () {\n global.gc();\n heapdump.writeSnapshot("./HZFE_HEAPSNAPSHOT/" + Date.now() + ".heapsnapshot");\n console.log("heapUsed:", process.memoryUsage().heapUsed);\n};\n\ncapture();\n\n/* \u53ef\u80fd\u6709\u5185\u5b58\u6cc4\u6f0f\u7684\u4ee3\u7801\u7247\u6bb5 start */\n// code\n/* \u53ef\u80fd\u6709\u5185\u5b58\u6cc4\u6f0f\u7684\u4ee3\u7801\u7247\u6bb5 end */\n\ncapture();\n')),(0,n.kt)("h2",{id:"\u53c2\u8003\u8d44\u6599"},"\u53c2\u8003\u8d44\u6599"),(0,n.kt)("ol",null,(0,n.kt)("li",{parentName:"ol"},(0,n.kt)("a",{parentName:"li",href:"https://developer.chrome.com/docs/devtools/"},"Chrome DevTools")),(0,n.kt)("li",{parentName:"ol"},(0,n.kt)("a",{parentName:"li",href:"https://developer.chrome.com/docs/devtools/memory-problems/"},"Fix memory problems"))))}u.isMDXComponent=!0}}]);
--------------------------------------------------------------------------------