<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] #### 1.什么是 generator 一個生成器,generator函數可以在函數執行到 yield的位置剎車,然后在需要的時候急需執行 + 使用 generator 1.創建一個*開頭的函數,賦值給聲明變量 2.obj.next()即可執行到第一個 yield那行,包括yield那行也會執行 ``` function* fn() { console.log(1); yield; // 中斷 console.log(2); } let obj = fn(); obj.next() // 1 ``` + 通過 next()傳參 ``` function* fn() { console.log(1); yield; // 中斷 console.log(2); let a = yield } let obj = fn(); obj.next(); // 1 obj.next() // 2 obj.next('給第二個 yield 傳入的參數') // 給第二個 yield 傳入的參數 ``` #### 2.無限next ```js // 無限 next function* add() { let num = 0; while (true) { yield ++num; } } const addNum = add(); console.log(addNum.next().value); // 1 console.log(addNum.next().value); // 2 ``` #### 3.生成器傳參 ```js function* message(name) { const msg = yield "hello" + name; console.log(msg); if (msg === "xx") { console.log("msg is xx"); } yield "hello" + name; } const fn = message("xuxu"); // 此時傳入xuxu console.log(fn.next()); // {value: 'helloxuxu', done: false} console.log(fn.next("xx")); // xx, console.log("msg is xx"), {value: 'helloxuxu', done: false} ```
                  <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>

                              哎呀哎呀视频在线观看