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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 函數式編程 ### 異步執行 ``` const curry=function (f) { return function () { const key=arguments setTimeout(function () { console.log(f.apply(f, key)); },0) } } const echo = curry(x=>x) echo("hello") console.log("world"); //world // hello ``` ### 緩存函數執行結果 ``` const memoize =function (f) { const cache=[]; return function () { const key = JSON.stringify(arguments) if (!cache[key]){ cache[key]=f.apply(this,arguments) } return cache[key] } } const add = memoize(x=>x+x) console.log(add(1));//2 console.log(add(1));//2 ``` ## 科里化 ``` function curry(func) { return function curried(...args) { // function.length 用來獲取函數的形參個數 // arguments.length 獲取的是實參個數 if (args.length >= func.length) { return func.apply(this, args) } return function (...args2) { return curried.apply(this, args.concat(args2)) } } } // 示意而已 function ajax(type, url, data) { var xhr = new XMLHttpRequest(); xhr.open(type, url, true); xhr.send(data); } // 雖然 ajax 這個函數非常通用,但在重復調用的時候參數冗余 ajax('POST', 'www.test.com', "name=kevin") ajax('POST', 'www.test2.com', "name=kevin") ajax('POST', 'www.test3.com', "name=kevin") // 利用 curry var ajaxCurry = curry(ajax); // 以 POST 類型請求數據 var post = ajaxCurry('POST'); post('www.test.com', "name=kevin"); // 以 POST 類型請求來自于 www.test.com 的數據 var postFromTest = post('www.test.com'); postFromTest("name=kevin"); ```
                  <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>

                              哎呀哎呀视频在线观看