{"id":444,"date":"2020-02-14T15:09:13","date_gmt":"2020-02-14T07:09:13","guid":{"rendered":"https:\/\/blog.cqdefxxx.com\/?p=444"},"modified":"2020-02-14T15:09:13","modified_gmt":"2020-02-14T07:09:13","slug":"%e9%97%ad%e5%8c%85%e7%9a%84%e5%ba%94%e7%94%a8_%e8%87%aa%e5%ae%9a%e4%b9%89js%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2020\/02\/14\/%e9%97%ad%e5%8c%85%e7%9a%84%e5%ba%94%e7%94%a8_%e8%87%aa%e5%ae%9a%e4%b9%89js%e6%a8%a1%e5%9d%97\/","title":{"rendered":"\u95ed\u5305\u7684\u5e94\u7528_\u81ea\u5b9a\u4e49JS\u6a21\u5757"},"content":{"rendered":"<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;title&gt;05_\u95ed\u5305\u7684\u5e94\u7528_\u81ea\u5b9a\u4e49JS\u6a21\u5757&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;!--\n\u95ed\u5305\u7684\u5e94\u75282 : \u5b9a\u4e49JS\u6a21\u5757\n  * \u5177\u6709\u7279\u5b9a\u529f\u80fd\u7684js\u6587\u4ef6\n  * \u5c06\u6240\u6709\u7684\u6570\u636e\u548c\u529f\u80fd\u90fd\u5c01\u88c5\u5728\u4e00\u4e2a\u51fd\u6570\u5185\u90e8(\u79c1\u6709\u7684)\n  * \u53ea\u5411\u5916\u66b4\u9732\u4e00\u4e2a\u5305\u4fe1n\u4e2a\u65b9\u6cd5\u7684\u5bf9\u8c61\u6216\u51fd\u6570\n  * \u6a21\u5757\u7684\u4f7f\u7528\u8005, \u53ea\u9700\u8981\u901a\u8fc7\u6a21\u5757\u66b4\u9732\u7684\u5bf9\u8c61\u8c03\u7528\u65b9\u6cd5\u6765\u5b9e\u73b0\u5bf9\u5e94\u7684\u529f\u80fd\n--&gt;\n&lt;script type=\"text\/javascript\" src=\"myModule.js\"&gt;&lt;\/script&gt;\n&lt;script type=\"text\/javascript\"&gt;\n  var module = myModule()\n  module.doSomething()\n  module.doOtherthing()\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>myModule.js\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">function myModule() {\n  \/\/\u79c1\u6709\u6570\u636e\n  var msg = 'My atguigu'\n  \/\/\u64cd\u4f5c\u6570\u636e\u7684\u51fd\u6570\n  function doSomething() {\n    console.log('doSomething() '+msg.toUpperCase())\n  }\n  function doOtherthing () {\n    console.log('doOtherthing() '+msg.toLowerCase())\n  }\n\n  \/\/\u5411\u5916\u66b4\u9732\u5bf9\u8c61(\u7ed9\u5916\u90e8\u4f7f\u7528\u7684\u65b9\u6cd5)\n  return {\n    doSomething: doSomething,\n    doOtherthing: doOtherthing\n  }\n}\n<\/code><\/pre>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;title&gt;05_\u95ed\u5305\u7684\u5e94\u7528_\u81ea\u5b9a\u4e49JS\u6a21\u57572&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;!--\n\u95ed\u5305\u7684\u5e94\u75282 : \u5b9a\u4e49JS\u6a21\u5757\n  * \u5177\u6709\u7279\u5b9a\u529f\u80fd\u7684js\u6587\u4ef6\n  * \u5c06\u6240\u6709\u7684\u6570\u636e\u548c\u529f\u80fd\u90fd\u5c01\u88c5\u5728\u4e00\u4e2a\u51fd\u6570\u5185\u90e8(\u79c1\u6709\u7684)\n  * \u53ea\u5411\u5916\u66b4\u9732\u4e00\u4e2a\u5305\u4fe1n\u4e2a\u65b9\u6cd5\u7684\u5bf9\u8c61\u6216\u51fd\u6570\n  * \u6a21\u5757\u7684\u4f7f\u7528\u8005, \u53ea\u9700\u8981\u901a\u8fc7\u6a21\u5757\u66b4\u9732\u7684\u5bf9\u8c61\u8c03\u7528\u65b9\u6cd5\u6765\u5b9e\u73b0\u5bf9\u5e94\u7684\u529f\u80fd\n--&gt;\n&lt;script type=\"text\/javascript\" src=\"myModule2.js\"&gt;&lt;\/script&gt;\n&lt;script type=\"text\/javascript\"&gt;\n  myModule2.doSomething()\n  myModule2.doOtherthing()\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>myModule2.js:<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">(function () {\n  \/\/\u79c1\u6709\u6570\u636e\n  var msg = 'My atguigu'\n  \/\/\u64cd\u4f5c\u6570\u636e\u7684\u51fd\u6570\n  function doSomething() {\n    console.log('doSomething() '+msg.toUpperCase())\n  }\n  function doOtherthing () {\n    console.log('doOtherthing() '+msg.toLowerCase())\n  }\n\n  \/\/\u5411\u5916\u66b4\u9732\u5bf9\u8c61(\u7ed9\u5916\u90e8\u4f7f\u7528\u7684\u65b9\u6cd5)\n  window.myModule2 = {\n    doSomething: doSomething,\n    doOtherthing: doOtherthing\n  }\n})()<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;!DOCTYPE html&gt; &lt;html lang=&#8221;en&#8221;&gt; &lt;head&gt; &lt;met","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[5],"_links":{"self":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/444"}],"collection":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/comments?post=444"}],"version-history":[{"count":0,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/444\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}