<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國際加速解決方案。 廣告
                [TOC] >[success] # commonjs-演示 **commonjs** 是 **nodejs** 的 **模塊化** ,可以使用 **module.exports** 和 **require** 將方法 **引入** 或 **導出** ,**module.exports** 和 **require** 是 **commonjs** 的關鍵字。 >[success] ## 單個方法導出與引入 **導出 a.js中的方法** ~~~ function add(a, b){ return a + b } // 導出add方法 module.exports = add ~~~ **b.js引入 a.js中的方法** ~~~ // 引入a.js中的add方法 const add = require('./a') // 計算 const sum = add(1, 2) // 打印結果 console.log(sum) ~~~ 最后在控制臺中打印 **node b.js** 運行 **b.js** 中的文件即可。 >[success] ## 多個方法導出與引入 **導出 a.js中的方法** ~~~ function add(a, b){ return a + b } function mul(a, b){ return a * b } // 導出多個方法 module.exports = { add, mul } ~~~ **b.js引入 a.js中的方法** ~~~ // 引入a.js中多個方法 const { add, mul } = require('./a') // 計算 const sum = add(1, 2) const result = mul(2, 2) // 打印結果 console.log(sum) console.log(result) ~~~ 最后在控制臺中打印 **node b.js** 運行 **b.js** 中的文件即可。 >[success] ## 用commonjs引入 npm 包 簡單的方法我們可以實現,像一些復雜的方法,就要 **npm** 來下載到本地使用,那么如何來 **引入npm** 的包呢,首先我們來初始化 **npm 環境** **初始化 npm 環境指令** ~~~ npm init -y ~~~ 初始化完成環境后,我們執行下面的指令安裝 **lodash** ,**lodash** 是工具方法的一個庫 ~~~ npm i lodash --save ~~~ 如果下載的很慢我們可以使用 **淘寶鏡像** 的地址,輸入 **https://npmmirror.com/** ,然后在剛才的指令后面加上 **--registry=https://registry.npmmirror.com** 就下載的很快了 ~~~ npm i lodash --save --registry=https://registry.npmmirror.com ~~~ 接下來在文件中引入 **lodash** ~~~ // 引入loadsh const _ = require('lodash') // 拼裝數組 const arr = _.concat([1,2], 3) // 打印 console.log(arr) ~~~ 最后在控制臺中打印**node b.js**運行**b.js**中的文件即可。
                  <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>

                              哎呀哎呀视频在线观看