<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 問題 你用CoffeeScript寫了一些功能模塊,你既希望它們能在客戶端跑在瀏覽器上,也希望能夠通過Node.js跑在服務端。 ## 方法 通過下面這樣的方式暴露這些功能模塊: ~~~ # simpleMath.coffee # these methods are private add = (a, b) -> a + b subtract = (a, b) -> a - b square = (x) -> x * x # create a namespace to export our public methods SimpleMath = exports? and exports or @SimpleMath = {} # items attached to our namespace are available in Node.js as well as client browsers class SimpleMath.Calculator add: add subtract: subtract square: square ~~~ ## 詳解 如上例,我們創建了一個新的命名空間——SimpleMath。如果`exports`存在,我們的類就做為一個Node.js模塊暴露出來,如果`exports`_不_存在,SimpleMath被加到全局中,然后就可以在頁面上使用它了。 在Node.js中,我們可以使用`require`命令包含這個模塊。 ~~~ $ node > var SimpleMath = require('./simpleMath'); undefined > var Calc = new SimpleMath.Calculator(); undefined > console.log("5 + 6 = ", Calc.add(5, 6)); 5 + 6 = 11 undefined > ~~~ 在頁面中,把它作為一個script引入進來我們就可以使用這個模塊了。 ~~~ <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>SimpleMath Module Example</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="simpleMath.js"></script> <script> jQuery(document).ready(function (){ var Calculator = new SimpleMath.Calculator(); var result = $('<li>').html("5 + 6 = " + Calculator.add(5, 6)); $('#SampleResults').append(result); }); </script> </head> <body> <h1>A SimpleMath Example</h1> <ul id="SampleResults"></ul> </body> </html> ~~~ 結果: # 一個簡單的例子 * 5 + 6 = 11
                  <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>

                              哎呀哎呀视频在线观看