<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                --- title: nodejs中的模塊與Commonjs規范 date: 2018-12-25 10:12:04 tags: nodejs --- ### 在 node 中的模塊 - nodejs 使用的是Commonjs 規范 - 具名的核心模塊 ,如 `fs,http,path` 等 - 第三方模塊,通過 npm 安裝到項目目錄 node_modules 中的模塊 - 用戶自己編寫的文件模塊, 即 xxx.js(exports 對象掛載導出,require 引入) - 核心模塊: 模塊名 - 第三方模塊: 模塊名 - 自己寫的模塊:地址 - node中沒有全局作用域,只有模塊作用域(即每個文件為一個單獨的模塊) - 模塊化可完全避免變量名沖突以及環境污染問題的 ### Commonjs 模塊規范 模塊間的通信規則 - 使用 `require` 導入 - 使用 `exports` 對象掛載導出或直接賦值給 module.exports 則默認導出該值 ```javascript // exports === module.exports // true 這里的內存地址是相同的 所以導出方法有兩種, 最好不要混著用 :) /* * 模塊內導出多個成員 * 通過掛載的方式進行導出 */ // a.js exports.a = '1' /* * 同等于 module.exports.a = '1' module 可省略, exports 和 module.exports 使用的是同一個內存地址 * 導出的模塊內容永遠掛載在 module 下的 exports屬性 */ exports.b = '2' exports.c = '3' //等同于 module.exports = { a:'1', b:'2', c:'3' } // b.js const aAccpet = require('./a') console.log(aAccpet.a) console.log(aAccpet.b) console.log(aAccpet.c) /* * 模塊內導出單個成員 * 通過賦值 module.exports的方式 */ //a.js 如果存在多個 module.exports賦值則最后一個會覆蓋掉前面的賦值 module.exports = (x,y) => x + y //錯誤寫法 exports = (x,y) => x+y //這種方式會改變 exports 的引用地址,無法掛載到 module.exports上面 //b.js const aAccept = require('./a') console.log(aAccept(2,4)) // 6 ``` 加載機制 (來自網絡) ![](https://ws4.sinaimg.cn/large/006tNbRwly1fyjz2w3qcgj30hy0lotbu.jpg) ### ip 地址與端口號 - ip地址用來定位請求計算機 - 端口號用來定位請求應用 - 所有聯網的應用程序都會有一個端口號的占用 - 同一個端口號在同一時間內僅能被一個程序使用 - 服務端開發中存在一些默認使用的端口號如 http服務的80端口,這種帶有含義的端口號開發中不應該使用
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看