{"id":338,"date":"2023-12-13T10:48:41","date_gmt":"2023-12-13T02:48:41","guid":{"rendered":"http:\/\/ericw.top\/?p=338"},"modified":"2023-12-13T10:54:46","modified_gmt":"2023-12-13T02:54:46","slug":"ecamscript-%e6%a0%87%e5%87%86","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=338","title":{"rendered":"ECAMScript \u6807\u51c6"},"content":{"rendered":"<h1 id=\"toc-0\">ECAMScript \u6807\u51c6<\/h1>\n<p><strong>\u9700\u6c42\uff1a<\/strong>\u5c01\u88c5\u5e76\u5bfc\u51fa\u57fa\u5730\u5740\u548c\u6c42\u6570\u7ec4\u6240\u6709\u5143\u7d20\u548c\u51fd\u6570<\/p>\n<h2 id=\"toc-1\">\u9ed8\u8ba4\u5bfc\u51fa\u548c\u5bfc\u5165<\/h2>\n<p><strong>\u9ed8\u8ba4\u6807\u51c6\u4f7f\u7528\uff1a<\/strong><\/p>\n<ol>\n<li>\u5bfc\u51fa\uff1a<code class=\"prettyprint\" >export default {}<\/code><\/li>\n<li>\u5bfc\u5165\uff1a<code class=\"prettyprint\" >import \u53d8\u91cf\u540d from &#039;\u6a21\u5757\u540d\u6216\u8def\u5f84&#039;<\/code><\/li>\n<\/ol>\n<p>Node.js\u9ed8\u8ba4\u652f\u6301CommonJS\u6807\u51c6\u8bed\u6cd5<\/p>\n<p>\u5982\u9700\u4f7f\u7528ECMAScript\u6807\u7816\u8bed\u6cd5\uff0c\u5728\u8fd0\u884c\u6a21\u5757\u6240\u5728\u7684\u6587\u4ef6\u5939\u65b0\u5efa<code class=\"prettyprint\" >Package.json<\/code>\u6587\u4ef6\uff0c\u5e76\u8bbe\u7f6e<code class=\"prettyprint\" >{&quot;type&quot;:&quot;module&quot;}<\/code><\/p>\n<p>\u6848\u4f8b\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u65b0\u5efapackage.json\u6587\u4ef6\uff0c\u5728\u91cc\u9762\u7f16\u8f91\uff1a<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-json\">{\n    &quot;type&quot;:&quot;module&quot;\n}<\/code><\/pre>\n<ol start=\"2\">\n<li>\u65b0\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u5757utils.js \uff0c\u91cc\u9762\u6709\u5c01\u88c5\u597d\u7684\u4ee3\u7801\u548c\u5bfc\u51fa\u65b9\u6cd5<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-js\">\/\/\u5c01\u88c5\u7684\u65b9\u6cd5\uff1a\nconst baseURL = &#039;http:\/\/hmajax.itheima.net&#039;\nconst getArraySum = arr =&gt; arr.reduce\n((sum,item) =&gt; sum += , 0)\n\n\/\/\u9ed8\u8ba4\u5bfc\u51fa\nexport default {\n    url:baseURL,\n    arraySum:getArraySum\n}<\/code><\/pre>\n<ol start=\"3\">\n<li>\u5728\u6211\u4eec\u9700\u8981\u4f7f\u7528\u7684\u5730\u65b9\u5bfc\u5165\u6211\u4eec\u7684\u81ea\u5b9a\u4e49\u6a21\u5757\u8def\u5f84\uff1a<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-js\">\/\/\u9ed8\u8ba4\u5bfc\u5165\nimport obj from &#039;.\/utils.js&#039;<\/code><\/pre>\n<h2 id=\"toc-2\">\u547d\u540d\u5bfc\u51fa\u548c\u5bfc\u5165<\/h2>\n<p><strong>\u547d\u540d\u5230\u5904\u548c\u5bfc\u5165\uff1a<\/strong><\/p>\n<ol>\n<li><strong>\u5bfc\u51fa\uff1a<\/strong><code class=\"prettyprint\" >export \u4fee\u9970\u5b9a\u4e49\u8bed\u53e5<\/code><\/li>\n<li><strong>\u5bfc\u5165\uff1a<\/strong><code class=\"prettyprint\" >import{\u540c\u540d\u53d8\u91cf} from &#039;\u6a21\u5757\u540d\u548c\u8def\u5f84&#039;<\/code><\/li>\n<\/ol>\n<p><strong>\u6309\u9700\u52a0\u8f7d\uff0c\u4f7f\u7528\u547d\u540d\u5bfc\u51fa\u548c\u5bfc\u5165<\/strong><\/p>\n<p><strong>\u5168\u90e8\u52a0\u8f7d\uff0c\u4f7f\u7528\u9ed8\u8ba4\u5bfc\u51fa\u548c\u5bfc\u5165<\/strong><\/p>\n<p>\u6848\u4f8b\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u65b0\u5efapackage.json\u6587\u4ef6\uff0c\u5728\u91cc\u9762\u7f16\u8f91\uff1a<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-json\">{\n    &quot;type&quot;:&quot;module&quot;\n}<\/code><\/pre>\n<ol start=\"2\">\n<li>\u547d\u540d\u5bfc\u51fa\u5c01\u88c5\u597d\u7684\u65b9\u6cd5<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-js\">\/**\n * \u76ee\u6807\uff1a\u57fa\u4e8e ECMAScript \u6807\u51c6\u8bed\u6cd5\uff0c\u5c01\u88c5\u5c5e\u6027\u548c\u65b9\u6cd5\u5e76&quot;\u547d\u540d&quot;\u5bfc\u51fa\n *\/\nexport const baseURL = &#039;http:\/\/hmajax.itheima.net&#039;\nexport const getArraySum = arr =&gt; arr.reduce((sum, item) =&gt; sum += item, 0)<\/code><\/pre>\n<ol start=\"3\">\n<li>\u547d\u540d\u5bfc\u5165\u5c01\u88c5\u597d\u7684\u65b9\u6cd5<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-js\">\/**\n * \u76ee\u6807\uff1a\u57fa\u4e8e ECMAScript \u6807\u51c6\u8bed\u6cd5\uff0c&quot;\u547d\u540d&quot;\u5bfc\u5165\uff0c\u5de5\u5177\u5c5e\u6027\u548c\u65b9\u6cd5\u4f7f\u7528\n *\/\n\/\/ \u547d\u540d\u5bfc\u5165\nimport {baseURL, getArraySum} from &#039;.\/utils.js&#039;\nconsole.log(obj)\nconsole.log(baseURL)\nconsole.log(getArraySum)\nconst result = getArraySum([10, 21, 33])\nconsole.log(result)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ECAMScript \u6807\u51c6 \u9700\u6c42\uff1a\u5c01\u88c5\u5e76\u5bfc\u51fa\u57fa\u5730\u5740\u548c\u6c42\u6570\u7ec4\u6240\u6709\u5143\u7d20\u548c\u51fd\u6570 \u9ed8\u8ba4\u5bfc\u51fa\u548c\u5bfc\u5165 \u9ed8\u8ba4\u6807\u51c6\u4f7f\u7528\uff1a \u5bfc\u51fa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":339,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/338"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=338"}],"version-history":[{"count":2,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":342,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions\/342"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/339"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}