-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaf7609e9.9cd44dcb.js
1 lines (1 loc) · 25.6 KB
/
af7609e9.9cd44dcb.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[42],{178:function(e,n,a){"use strict";a.r(n),a.d(n,"frontMatter",(function(){return l})),a.d(n,"metadata",(function(){return r})),a.d(n,"rightToc",(function(){return p})),a.d(n,"default",(function(){return O}));var t=a(2),b=a(9),c=(a(0),a(199)),l={title:"\u4ee3\u7801\u89c4\u8303"},r={id:"js/code",title:"\u4ee3\u7801\u89c4\u8303",description:"## \u7f16\u7801\u89c4\u8303",source:"@site/docs/js/code.md",permalink:"/jdc_fe_guide/docs/js/code",editUrl:"https://git.jd.com/JDC_FE/jdc_fe_guide/tree/master/docs/js/code.md",sidebar:"someSidebar",previous:{title:"\u5a92\u4f53\u67e5\u8be2",permalink:"/jdc_fe_guide/docs/css/query"},next:{title:"\u8bed\u8a00\u89c4\u8303",permalink:"/jdc_fe_guide/docs/js/language"}},p=[{value:"\u7f16\u7801\u89c4\u8303",id:"\u7f16\u7801\u89c4\u8303",children:[{value:"\u5355\u884c\u4ee3\u7801\u5757",id:"\u5355\u884c\u4ee3\u7801\u5757",children:[]},{value:"\u5927\u62ec\u53f7\u98ce\u683c",id:"\u5927\u62ec\u53f7\u98ce\u683c",children:[]},{value:"\u53d8\u91cf\u547d\u540d",id:"\u53d8\u91cf\u547d\u540d",children:[]},{value:"\u62d6\u5c3e\u9017\u53f7",id:"\u62d6\u5c3e\u9017\u53f7",children:[]},{value:"\u9017\u53f7\u7a7a\u683c",id:"\u9017\u53f7\u7a7a\u683c",children:[]},{value:"\u9017\u53f7\u98ce\u683c",id:"\u9017\u53f7\u98ce\u683c",children:[]},{value:"\u8ba1\u7b97\u5c5e\u6027\u7684\u7a7a\u683c",id:"\u8ba1\u7b97\u5c5e\u6027\u7684\u7a7a\u683c",children:[]},{value:"\u62d6\u5c3e\u6362\u884c",id:"\u62d6\u5c3e\u6362\u884c",children:[]},{value:"\u51fd\u6570\u8c03\u7528",id:"\u51fd\u6570\u8c03\u7528",children:[]},{value:"\u7f29\u8fdb",id:"\u7f29\u8fdb",children:[]},{value:"\u5bf9\u8c61\u5b57\u9762\u91cf\u7684\u952e\u503c\u7f29\u8fdb",id:"\u5bf9\u8c61\u5b57\u9762\u91cf\u7684\u952e\u503c\u7f29\u8fdb",children:[]},{value:"\u6784\u9020\u51fd\u6570\u9996\u5b57\u6bcd\u5927\u5199",id:"\u6784\u9020\u51fd\u6570\u9996\u5b57\u6bcd\u5927\u5199",children:[]},{value:"\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570",id:"\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570",children:[]},{value:"\u94fe\u5f0f\u8c03\u7528",id:"\u94fe\u5f0f\u8c03\u7528",children:[]},{value:"\u7a7a\u884c",id:"\u7a7a\u884c",children:[]},{value:"\u94fe\u5f0f\u8d4b\u503c",id:"\u94fe\u5f0f\u8d4b\u503c",children:[]},{value:"\u53d8\u91cf\u58f0\u660e",id:"\u53d8\u91cf\u58f0\u660e",children:[]},{value:"\u5206\u53f7",id:"\u5206\u53f7",children:[]},{value:"\u4ee3\u7801\u5757\u7a7a\u683c",id:"\u4ee3\u7801\u5757\u7a7a\u683c",children:[]},{value:"\u51fd\u6570\u58f0\u660e\u7684\u7a7a\u683c",id:"\u51fd\u6570\u58f0\u660e\u7684\u7a7a\u683c",children:[]},{value:"\u64cd\u4f5c\u7b26\u7684\u7a7a\u683c",id:"\u64cd\u4f5c\u7b26\u7684\u7a7a\u683c",children:[]},{value:"BOM",id:"bom",children:[]}]}],j={rightToc:p};function O(e){var n=e.components,a=Object(b.a)(e,["components"]);return Object(c.b)("wrapper",Object(t.a)({},j,a,{components:n,mdxType:"MDXLayout"}),Object(c.b)("h2",{id:"\u7f16\u7801\u89c4\u8303"},"\u7f16\u7801\u89c4\u8303"),Object(c.b)("p",null,"\u7edf\u4e00\u56e2\u961f\u7684\u7f16\u7801\u89c4\u8303\uff0c\u6709\u52a9\u4e8e\u4ee3\u7801\u7684\u7ef4\u62a4\u3002\u672c\u7ae0\u662f\u4f20\u7edf\u610f\u4e49\u4e0a\u7684 ",Object(c.b)("inlineCode",{parentName:"p"},"Style Guideline"),"\uff0c\u76ee\u7684\u662f\u7edf\u4e00\u4e00\u4e9b\u76f8\u5bf9\u4e3b\u89c2\u5316\u7684\u4ee3\u7801\u98ce\u683c\u3002"),Object(c.b)("h3",{id:"\u5355\u884c\u4ee3\u7801\u5757"},"\u5355\u884c\u4ee3\u7801\u5757"),Object(c.b)("p",null,"\u5728\u5355\u884c\u4ee3\u7801\u5757\u4e2d\u4f7f\u7528\u7a7a\u683c"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"function foo () {return true}\nif (foo) {bar = 0}\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"function foo () { return true }\nif (foo) { bar = 0 }\n")),Object(c.b)("h3",{id:"\u5927\u62ec\u53f7\u98ce\u683c"},"\u5927\u62ec\u53f7\u98ce\u683c"),Object(c.b)("p",null,"\u5728\u7f16\u7a0b\u8fc7\u7a0b\u4e2d\uff0c\u5927\u62ec\u53f7\u98ce\u683c\u4e0e\u7f29\u8fdb\u98ce\u683c\u7d27\u5bc6\u8054\u7cfb\uff0c\u7528\u6765\u63cf\u8ff0\u5927\u62ec\u53f7\u76f8\u5bf9\u4ee3\u7801\u5757\u4f4d\u7f6e\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u3002\u5728 JavaScript \u4e2d\uff0c\u4e3b\u8981\u6709\u4e09\u79cd\u98ce\u683c\uff0c\u5982\u4e0b\uff1a"),Object(c.b)("ul",null,Object(c.b)("li",{parentName:"ul"},Object(c.b)("p",{parentName:"li"},Object(c.b)("strong",{parentName:"p"},"One True Brace Style")),Object(c.b)("pre",{parentName:"li"},Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"if (foo) {\n bar()\n} else {\n baz()\n}\n"))),Object(c.b)("li",{parentName:"ul"},Object(c.b)("p",{parentName:"li"},Object(c.b)("strong",{parentName:"p"},"Stroustrup")),Object(c.b)("pre",{parentName:"li"},Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"if (foo) {\n bar()\n}\nelse {\n baz()\n}\n"))),Object(c.b)("li",{parentName:"ul"},Object(c.b)("p",{parentName:"li"},Object(c.b)("strong",{parentName:"p"},"Allman")),Object(c.b)("pre",{parentName:"li"},Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"if (foo)\n{\n bar()\n}\nelse\n{\n baz()\n}\n")))),Object(c.b)("p",null,"\u6211\u4eec\u56e2\u961f\u7ea6\u5b9a\u4f7f\u7528 ",Object(c.b)("inlineCode",{parentName:"p"},"One True Brace Style")," \u98ce\u683c"),Object(c.b)("h3",{id:"\u53d8\u91cf\u547d\u540d"},"\u53d8\u91cf\u547d\u540d"),Object(c.b)("p",null,"\u5f53\u547d\u540d\u53d8\u91cf\u65f6\uff0c\u4e3b\u6d41\u5206\u4e3a\u9a7c\u5cf0\u5f0f\u547d\u540d\uff08variableName\uff09\u548c\u4e0b\u5212\u7ebf\u547d\u540d\uff08variable_name\uff09\u4e24\u5927\u9635\u8425\u3002"),Object(c.b)("blockquote",null,Object(c.b)("p",{parentName:"blockquote"},"\u56e2\u961f\u7ea6\u5b9a\u4f7f\u7528\u9a7c\u5cf0\u5f0f\u547d\u540d")),Object(c.b)("h3",{id:"\u62d6\u5c3e\u9017\u53f7"},"\u62d6\u5c3e\u9017\u53f7"),Object(c.b)("p",null,"\u5728 ECMAScript5 \u91cc\u9762\uff0c\u5bf9\u8c61\u5b57\u9762\u91cf\u4e2d\u7684\u62d6\u5c3e\u9017\u53f7\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u5728 IE8\uff08\u975e IE8 \u6587\u6863\u6a21\u5f0f\uff09\u4e0b\uff0c\u5f53\u51fa\u73b0\u62d6\u5c3e\u9017\u53f7\uff0c\u5219\u4f1a\u629b\u51fa\u9519\u8bef\u3002"),Object(c.b)("p",null,"\u62d6\u5c3e\u9017\u53f7\u7684\u4f8b\u5b50\uff1a"),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var foo = {\n name: 'foo',\n age: '22',\n}\n")),Object(c.b)("p",null,"\u62d6\u5c3e\u9017\u53f7\u7684\u597d\u5904\u662f\uff0c\u7b80\u5316\u4e86\u5bf9\u8c61\u548c\u6570\u7ec4\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4fee\u6539\u65b0\u589e\u7684\u884c\u5373\u53ef\uff0c\u5e76\u4e0d\u4f1a\u589e\u52a0\u5dee\u5f02\u5316\u7684\u4ee3\u7801\u884c\u6570\u3002"),Object(c.b)("blockquote",null,Object(c.b)("p",{parentName:"blockquote"},"\u56e0\u4e3a\u62d6\u5c3e\u9017\u53f7\u6709\u597d\u4e5f\u6709\u4e0d\u597d\uff0c\u6240\u4ee5\u56e2\u961f\u7ea6\u5b9a\u5141\u8bb8\u5728\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u6216\u5c5e\u6027\u4e0e\u95ed\u62ec\u53f7 ",Object(c.b)("inlineCode",{parentName:"p"},"]")," \u6216 ",Object(c.b)("inlineCode",{parentName:"p"},"}")," \u5728\u4e0d\u540c\u884c\u65f6\uff0c\u53ef\u4ee5\uff08\u4f46\u4e0d\u8981\u6c42\uff09\u4f7f\u7528\u62d6\u5c3e\u9017\u53f7\u3002\u5f53\u5728\u540c\u4e00\u884c\u65f6\uff0c\u7981\u6b62\u4f7f\u7528\u62d6\u5c3e\u9017\u53f7\u3002")),Object(c.b)("h3",{id:"\u9017\u53f7\u7a7a\u683c"},"\u9017\u53f7\u7a7a\u683c"),Object(c.b)("p",null,"\u9017\u53f7\u524d\u540e\u7684\u7a7a\u683c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u56e2\u961f\u7ea6\u5b9a\u5728\u9017\u53f7\u540e\u9762\u4f7f\u7528\u7a7a\u683c\uff0c\u9017\u53f7\u524d\u9762\u4e0d\u52a0\u7a7a\u683c\u3002"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var foo = 1,bar = 2\nvar foo = 1 , bar = 2\nvar foo = 1 ,bar = 2\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var foo = 1, bar = 2\n")),Object(c.b)("h3",{id:"\u9017\u53f7\u98ce\u683c"},"\u9017\u53f7\u98ce\u683c"),Object(c.b)("p",null,"\u9017\u53f7\u5206\u9694\u5217\u8868\u65f6\uff0c\u5728 JavaScript \u4e2d\u4e3b\u8981\u6709\u4e24\u79cd\u9017\u53f7\u98ce\u683c\uff1a"),Object(c.b)("ul",null,Object(c.b)("li",{parentName:"ul"},"\u6807\u51c6\u98ce\u683c\uff0c\u9017\u53f7\u653e\u7f6e\u5728\u5f53\u524d\u884c\u7684\u672b\u5c3e"),Object(c.b)("li",{parentName:"ul"},"\u9017\u53f7\u524d\u7f6e\u98ce\u683c\uff0c\u9017\u53f7\u653e\u7f6e\u5728\u4e0b\u4e00\u884c\u7684\u5f00\u59cb\u4f4d\u7f6e")),Object(c.b)("blockquote",null,Object(c.b)("p",{parentName:"blockquote"},"\u56e2\u961f\u7ea6\u5b9a\u4f7f\u7528\u6807\u51c6\u98ce\u683c")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var foo = 1\n,\nbar = 2\n\nvar foo = 1\n, bar = 2\n\nvar foo = ['name'\n , 'age']\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var foo = 1,\n bar = 2\n\nvar foo = ['name',\n 'age']\n")),Object(c.b)("h3",{id:"\u8ba1\u7b97\u5c5e\u6027\u7684\u7a7a\u683c"},"\u8ba1\u7b97\u5c5e\u6027\u7684\u7a7a\u683c"),Object(c.b)("p",null,"\u56e2\u961f\u7ea6\u5b9a\u5728\u5bf9\u8c61\u7684\u8ba1\u7b97\u5c5e\u6027\u5185\uff0c\u7981\u6b62\u4f7f\u7528\u7a7a\u683c"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"obj['foo' ]\nobj[ 'foo']\nobj[ 'foo' ]\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"obj['foo']\n")),Object(c.b)("h3",{id:"\u62d6\u5c3e\u6362\u884c"},"\u62d6\u5c3e\u6362\u884c"),Object(c.b)("p",null,"\u5728\u975e\u7a7a\u6587\u4ef6\u4e2d\uff0c\u5b58\u5728\u62d6\u5c3e\u6362\u884c\u662f\u4e00\u4e2a\u5e38\u89c1\u7684 ",Object(c.b)("inlineCode",{parentName:"p"},"UNIX")," \u98ce\u683c\uff0c\u5b83\u7684\u597d\u5904\u662f\u53ef\u4ee5\u65b9\u4fbf\u5728\u4e32\u8054\u548c\u8ffd\u52a0\u6587\u4ef6\u65f6\u4e0d\u4f1a\u6253\u65ad ",Object(c.b)("inlineCode",{parentName:"p"},"Shell")," \u7684\u63d0\u793a\u3002\u5728\u65e5\u5e38\u7684\u9879\u76ee\u4e2d\uff0c\u4fdd\u7559\u62d6\u5c3e\u6362\u884c\u7684\u597d\u5904\u662f\uff0c\u53ef\u4ee5\u51cf\u5c11\u7248\u672c\u63a7\u5236\u65f6\u7684\u4ee3\u7801\u51b2\u7a81\u3002"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"function func () {\n // do something\n}\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"function func () {\n // do something\n}\n // \u6b64\u5904\u662f\u65b0\u7684\u4e00\u884c\n")),Object(c.b)("blockquote",null,Object(c.b)("p",{parentName:"blockquote"},"\u53ef\u4ee5\u901a\u8fc7 .editorconfig \u6dfb\u52a0 EOL")),Object(c.b)("h3",{id:"\u51fd\u6570\u8c03\u7528"},"\u51fd\u6570\u8c03\u7528"),Object(c.b)("p",null,"\u4e3a\u4e86\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff0c\u56e2\u961f\u7ea6\u5b9a\u5728\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u7981\u6b62\u4f7f\u7528\u7a7a\u683c"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"fn ()\nfn\n()\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"fn()\n")),Object(c.b)("h3",{id:"\u7f29\u8fdb"},"\u7f29\u8fdb"),Object(c.b)("p",null,"\u4ee3\u7801\u4fdd\u6301\u4e00\u81f4\u7684\u7f29\u8fdb\uff0c\u662f\u4f5c\u4e3a\u5de5\u7a0b\u5e08\u7684\u804c\u4e1a\u7d20\u517b\u3002\u4f46\u7f29\u8fdb\u7528\u4e24\u4e2a\u7a7a\u683c\uff0c\u8fd8\u662f\u56db\u4e2a\u7a7a\u683c\uff0c\u662f\u7528 ",Object(c.b)("inlineCode",{parentName:"p"},"Tab")," \u8fd8\u662f\u7a7a\u683c\u5462\uff1f\u8fd9\u6837\u7684\u4e89\u8bba\u592a\u591a\u4e86\uff0c\u4e5f\u5f97\u4e0d\u51fa\u7b54\u6848\u3002\u672c\u89c4\u8303\u7ed3\u5408\u4e86\u5e02\u9762\u4e0a\u4f18\u79c0\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u59d1\u4e14\u7ea6\u5b9a\u4f7f\u7528 ",Object(c.b)("inlineCode",{parentName:"p"},"\u7a7a\u683c")," \u6765\u7f29\u8fdb\uff0c\u800c\u4e14\u7f29\u8fdb\u4f7f\u7528\u4e24\u4e2a\u7a7a\u683c\u3002"),Object(c.b)("p",null,"\u90a3\u662f\u4e0d\u662f\u4e0d\u80fd\u4f7f\u7528 ",Object(c.b)("inlineCode",{parentName:"p"},"Tab")," \u8fdb\u884c\u7f29\u8fdb\u4e86\uff1f\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e ",Object(c.b)("inlineCode",{parentName:"p"},".editorconfig")," \uff0c\u5c06 ",Object(c.b)("inlineCode",{parentName:"p"},"Tab")," \u81ea\u52a8\u8f6c\u6362\u4e3a\u7a7a\u683c\u3002"),Object(c.b)("h3",{id:"\u5bf9\u8c61\u5b57\u9762\u91cf\u7684\u952e\u503c\u7f29\u8fdb"},"\u5bf9\u8c61\u5b57\u9762\u91cf\u7684\u952e\u503c\u7f29\u8fdb"),Object(c.b)("p",null,"\u56e2\u961f\u7ea6\u5b9a\u5bf9\u8c61\u5b57\u9762\u91cf\u7684\u952e\u548c\u503c\u4e4b\u95f4\u4e0d\u80fd\u5b58\u5728\u7a7a\u683c\uff0c\u4e14\u8981\u6c42\u5bf9\u8c61\u5b57\u9762\u91cf\u7684\u5192\u53f7\u548c\u503c\u4e4b\u95f4\u5b58\u5728\u4e00\u4e2a\u7a7a\u683c"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var obj = { 'foo' : 'haha' }\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var obj = { 'foo': 'haha' }\n")),Object(c.b)("h3",{id:"\u6784\u9020\u51fd\u6570\u9996\u5b57\u6bcd\u5927\u5199"},"\u6784\u9020\u51fd\u6570\u9996\u5b57\u6bcd\u5927\u5199"),Object(c.b)("p",null,"\u5728 JavaScript \u4e2d ",Object(c.b)("inlineCode",{parentName:"p"},"new")," \u64cd\u4f5c\u7b26\u7528\u6765\u521b\u5efa\u67d0\u4e2a\u7279\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u8be5\u7c7b\u578b\u7684\u5bf9\u8c61\u662f\u7531\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u8868\u793a\u7684\u3002\u7531\u4e8e\u6784\u9020\u51fd\u6570\u53ea\u662f\u5e38\u89c4\u51fd\u6570\uff0c\u552f\u4e00\u533a\u522b\u662f\u4f7f\u7528 ",Object(c.b)("inlineCode",{parentName:"p"},"new")," \u6765\u8c03\u7528\u3002\u6240\u4ee5\u6211\u4eec\u56e2\u961f\u7ea6\u5b9a\u6784\u9020\u51fd\u6570\u7684\u9996\u5b57\u6bcd\u8981\u5927\u5c0f\uff0c\u4ee5\u6b64\u6765\u533a\u5206\u6784\u9020\u51fd\u6570\u548c\u666e\u901a\u51fd\u6570\u3002"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var fooItem = new foo()\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var fooItem = new Foo()\n")),Object(c.b)("h3",{id:"\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570"},"\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570"),Object(c.b)("p",null,"\u5728 JavaScript \u4e2d\uff0c\u901a\u8fc7 ",Object(c.b)("inlineCode",{parentName:"p"},"new")," \u8c03\u7528\u6784\u9020\u51fd\u6570\u65f6\uff0c\u5982\u679c\u4e0d\u5e26\u53c2\u6570\uff0c\u53ef\u4ee5\u7701\u7565\u540e\u9762\u7684\u5706\u62ec\u53f7\u3002\u4f46\u8fd9\u6837\u4f1a\u9020\u6210\u4e0e\u6574\u4f53\u7684\u4ee3\u7801\u98ce\u683c\u4e0d\u4e00\u81f4\uff0c\u6240\u4ee5\u56e2\u961f\u7ea6\u5b9a\u4f7f\u7528\u5706\u62ec\u53f7"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var person = new Person\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var person = new Person()\n")),Object(c.b)("h3",{id:"\u94fe\u5f0f\u8c03\u7528"},"\u94fe\u5f0f\u8c03\u7528"),Object(c.b)("p",null,"\u94fe\u5f0f\u8c03\u7528\u5982\u679c\u653e\u5728\u540c\u4e00\u884c\uff0c\u5f80\u5f80\u4f1a\u9020\u6210\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u5dee\uff0c\u4f46\u6709\u4e9b\u65f6\u5019\uff0c\u77ed\u7684\u94fe\u5f0f\u8c03\u7528\u5e76\u4e0d\u4f1a\u5f71\u54cd\u7f8e\u89c2\u3002\u6240\u4ee5\u672c\u89c4\u8303\u7ea6\u5b9a\u4e00\u884c\u6700\u591a\u53ea\u80fd\u6709\u56db\u4e2a\u94fe\u5f0f\u8c03\u7528\uff0c\u8d85\u8fc7\u5c31\u8981\u6c42\u6362\u884c\u3002"),Object(c.b)("h3",{id:"\u7a7a\u884c"},"\u7a7a\u884c"),Object(c.b)("p",null,"\u7a7a\u767d\u884c\u5bf9\u4e8e\u5206\u79bb\u4ee3\u7801\u903b\u8f91\u6709\u5e2e\u52a9\uff0c\u4f46\u8fc7\u591a\u7684\u7a7a\u884c\u4f1a\u5360\u636e\u5c4f\u5e55\u7684\u7a7a\u95f4\uff0c\u5f71\u54cd\u53ef\u8bfb\u6027\u3002\u56e2\u961f\u7ea6\u5b9a\u6700\u5927\u8fde\u7eed\u7a7a\u884c\u6570\u4e3a 2"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var a = 1\n\n\n\nvar b = 2\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var a = 1\n\n\nvar b = 2\n")),Object(c.b)("h3",{id:"\u94fe\u5f0f\u8d4b\u503c"},"\u94fe\u5f0f\u8d4b\u503c"),Object(c.b)("p",null,"\u94fe\u5f0f\u8d4b\u503c\u5bb9\u6613\u9020\u6210\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u5dee\uff0c\u6240\u4ee5\u56e2\u961f\u7ea6\u5b9a\u7981\u6b62\u4f7f\u7528\u94fe\u5f0f\u8d4b\u503c"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var a = b = c = 1\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var a = 1\nvar b = 1\nvar c = 1\n")),Object(c.b)("h3",{id:"\u53d8\u91cf\u58f0\u660e"},"\u53d8\u91cf\u58f0\u660e"),Object(c.b)("p",null,"JavaScript \u5141\u8bb8\u5728\u4e00\u4e2a\u58f0\u660e\u4e2d\uff0c\u58f0\u660e\u591a\u4e2a\u53d8\u91cf\u3002\u56e2\u961f\u7ea6\u5b9a\u5728\u58f0\u660e\u53d8\u91cf\u65f6\uff0c\u4e00\u4e2a\u58f0\u660e\u53ea\u80fd\u6709\u4e00\u4e2a\u53d8\u91cf"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var a, b, c\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var a\nvar b\nvar c\n")),Object(c.b)("h3",{id:"\u5206\u53f7"},"\u5206\u53f7"),Object(c.b)("p",null,"JavaScript \u5728\u6240\u6709\u7c7b C \u8bed\u8a00\u4e2d\u662f\u6bd4\u8f83\u72ec\u7279\u7684\uff0c\u5b83\u4e0d\u9700\u8981\u5728\u6bcf\u4e2a\u8bed\u53e5\u7684\u672b\u5c3e\u6709\u5206\u53f7\u3002\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0cJavaScript \u5f15\u64ce\u53ef\u4ee5\u786e\u5b9a\u4e00\u4e2a\u5206\u53f7\u5e94\u8be5\u5728\u4ec0\u4e48\u4f4d\u7f6e\u7136\u540e\u81ea\u52a8\u6dfb\u52a0\u5b83\u3002\u6b64\u7279\u5f81\u88ab\u79f0\u4e3a \u81ea\u52a8\u5206\u53f7\u63d2\u5165 (ASI)\uff0c\u88ab\u8ba4\u4e3a\u662f JavaScript \u4e2d\u8f83\u4e3a\u6709\u4e89\u8bae\u7684\u7279\u5f81\u3002"),Object(c.b)("p",null,"\u56e2\u961f\u4e2d\u5bf9\u4e8e\u662f\u5426\u5e94\u8be5\u4f7f\u7528\u5206\u53f7\uff0c\u4e5f\u6709\u8bb8\u591a\u4e89\u8bba\uff0c\u672c\u89c4\u8303\u63a8\u8350\u4e0d\u4f7f\u7528\u5206\u53f7\uff0c\u56e0\u4e3a\u6211\u4eec\u8ba4\u4e3a\u597d\u7684\u5de5\u7a0b\u5e08\u5e94\u8be5\u77e5\u9053\u4ec0\u4e48\u65f6\u5019\u8be5\u52a0\uff0c\u4ec0\u4e48\u65f6\u5019\u4e0d\u8be5\u52a0\u3002"),Object(c.b)("p",null,"\u76f8\u5173\u53c2\u8003 \uff1a",Object(c.b)("a",Object(t.a)({parentName:"p"},{href:"http://eslint.org/docs/rules/semi"}),"semi")),Object(c.b)("h3",{id:"\u4ee3\u7801\u5757\u7a7a\u683c"},"\u4ee3\u7801\u5757\u7a7a\u683c"),Object(c.b)("p",null,"\u4e00\u81f4\u6027\u662f\u4efb\u4f55\u98ce\u683c\u6307\u5357\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\u3002\u867d\u7136\u5728\u54ea\u91cc\u653e\u7f6e\u5757\u7684\u5f00\u62ec\u53f7\u7eaf\u5c5e\u4e2a\u4eba\u504f\u597d\uff0c\u4f46\u5728\u6574\u4e2a\u9879\u76ee\u4e2d\u5e94\u8be5\u4fdd\u6301\u4e00\u81f4\u3002\u4e0d\u4e00\u81f4\u7684\u98ce\u683c\u5c06\u4f1a\u5206\u6563\u8bfb\u8005\u9605\u8bfb\u4ee3\u7801\u7684\u6ce8\u610f\u529b\u3002"),Object(c.b)("blockquote",null,Object(c.b)("p",{parentName:"blockquote"},"\u56e2\u961f\u7ea6\u5b9a\u4ee3\u7801\u5757\u524d\u8981\u6dfb\u52a0\u7a7a\u683c")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"if (a){\n b()\n}\n\nfunction a (){}\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"if (a) {\n b()\n}\n\nfunction a () {}\n")),Object(c.b)("h3",{id:"\u51fd\u6570\u58f0\u660e\u7684\u7a7a\u683c"},"\u51fd\u6570\u58f0\u660e\u7684\u7a7a\u683c"),Object(c.b)("p",null,"\u5f53\u683c\u5f0f\u5316\u4e00\u4e2a\u51fd\u6570\uff0c\u51fd\u6570\u540d\u6216 function \u5173\u952e\u5b57\u4e0e\u5de6\u62ec\u53f7\u4e4b\u95f4\u5141\u8bb8\u6709\u7a7a\u767d\u3002\u547d\u540d\u51fd\u6570\u8981\u6c42\u51fd\u6570\u540d\u548c function \u5173\u952e\u5b57\u4e4b\u95f4\u6709\u7a7a\u683c\uff0c\u4f46\u662f\u533f\u540d\u51fd\u6570\u8981\u6c42\u4e0d\u52a0\u7a7a\u683c\u3002"),Object(c.b)("blockquote",null,Object(c.b)("p",{parentName:"blockquote"},"\u56e2\u961f\u7ea6\u5b9a\u51fd\u6570\u62ec\u53f7\u524d\u8981\u52a0\u7a7a\u683c")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"function func(x) {\n // ...\n}\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"function func (x) {\n // ...\n}\n")),Object(c.b)("h3",{id:"\u64cd\u4f5c\u7b26\u7684\u7a7a\u683c"},"\u64cd\u4f5c\u7b26\u7684\u7a7a\u683c"),Object(c.b)("p",null,"\u56e2\u961f\u7ea6\u5b9a\u64cd\u4f5c\u7b26\u524d\u540e\u90fd\u9700\u8981\u6dfb\u52a0\u7a7a\u683c"),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u4e0d\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var sum = 1+2\n")),Object(c.b)("p",null,Object(c.b)("em",{parentName:"p"},"\u63a8\u8350")),Object(c.b)("pre",null,Object(c.b)("code",Object(t.a)({parentName:"pre"},{className:"language-js"}),"var sum = 1 + 2\n")),Object(c.b)("h3",{id:"bom"},"BOM"),Object(c.b)("p",null,"Unicode \u5b57\u8282\u987a\u5e8f\u6807\u8bb0 (BOM) \u7528\u6765\u6307\u5b9a\u4ee3\u7801\u5355\u5143\u662f\u9ad8\u5b57\u8282\u5e8f\u8fd8\u662f\u4f4e\u5b57\u8282\u5e8f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u662f\u9ad8\u4f4d\u5728\u524d\u8fd8\u662f\u4f4e\u4f4d\u5728\u524d\u3002UTF-8 \u4e0d\u9700\u8981 BOM \u6765\u8868\u660e\u5b57\u8282\u987a\u5e8f\uff0c\u56e0\u4e3a\u5355\u4e2a\u5b57\u8282\u5e76\u4e0d\u5f71\u54cd\u5b57\u8282\u987a\u5e8f\u3002"),Object(c.b)("p",null,"\u76f8\u4fe1\u4e0d\u5c11\u540c\u5b66\u9047\u5230\u8fc7 BOM \u7684\u5751\uff0c\u8fd9\u91cc\u4e0d\u591a\u8bf4\u4e86\uff0c\u5207\u8bb0\u4e0d\u8981\u4f7f\u7528 windows \u7684\u8bb0\u4e8b\u672c\u6539\u4ee3\u7801\uff01"))}O.isMDXComponent=!0},199:function(e,n,a){"use strict";a.d(n,"a",(function(){return o})),a.d(n,"b",(function(){return m}));var t=a(0),b=a.n(t);function c(e,n,a){return n in e?Object.defineProperty(e,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[n]=a,e}function l(e,n){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n&&(t=t.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),a.push.apply(a,t)}return a}function r(e){for(var n=1;n<arguments.length;n++){var a=null!=arguments[n]?arguments[n]:{};n%2?l(Object(a),!0).forEach((function(n){c(e,n,a[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):l(Object(a)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(a,n))}))}return e}function p(e,n){if(null==e)return{};var a,t,b=function(e,n){if(null==e)return{};var a,t,b={},c=Object.keys(e);for(t=0;t<c.length;t++)a=c[t],n.indexOf(a)>=0||(b[a]=e[a]);return b}(e,n);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(t=0;t<c.length;t++)a=c[t],n.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(b[a]=e[a])}return b}var j=b.a.createContext({}),O=function(e){var n=b.a.useContext(j),a=n;return e&&(a="function"==typeof e?e(n):r({},n,{},e)),a},o=function(e){var n=O(e.components);return b.a.createElement(j.Provider,{value:n},e.children)},u={inlineCode:"code",wrapper:function(e){var n=e.children;return b.a.createElement(b.a.Fragment,{},n)}},i=Object(t.forwardRef)((function(e,n){var a=e.components,t=e.mdxType,c=e.originalType,l=e.parentName,j=p(e,["components","mdxType","originalType","parentName"]),o=O(a),i=t,m=o["".concat(l,".").concat(i)]||o[i]||u[i]||c;return a?b.a.createElement(m,r({ref:n},j,{components:a})):b.a.createElement(m,r({ref:n},j))}));function m(e,n){var a=arguments,t=n&&n.mdxType;if("string"==typeof e||t){var c=a.length,l=new Array(c);l[0]=i;var r={};for(var p in n)hasOwnProperty.call(n,p)&&(r[p]=n[p]);r.originalType=e,r.mdxType="string"==typeof e?e:t,l[1]=r;for(var j=2;j<c;j++)l[j]=a[j];return b.a.createElement.apply(null,l)}return b.a.createElement.apply(null,a)}i.displayName="MDXCreateElement"}}]);