久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='0YpdT'></tfoot>

      <bdo id='0YpdT'></bdo><ul id='0YpdT'></ul>

    <small id='0YpdT'></small><noframes id='0YpdT'>

  1. <legend id='0YpdT'><style id='0YpdT'><dir id='0YpdT'><q id='0YpdT'></q></dir></style></legend>

  2. <i id='0YpdT'><tr id='0YpdT'><dt id='0YpdT'><q id='0YpdT'><span id='0YpdT'><b id='0YpdT'><form id='0YpdT'><ins id='0YpdT'></ins><ul id='0YpdT'></ul><sub id='0YpdT'></sub></form><legend id='0YpdT'></legend><bdo id='0YpdT'><pre id='0YpdT'><center id='0YpdT'></center></pre></bdo></b><th id='0YpdT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0YpdT'><tfoot id='0YpdT'></tfoot><dl id='0YpdT'><fieldset id='0YpdT'></fieldset></dl></div>

      承諾,如何將變量傳遞給 .then 函數

      Promises, how to pass variable into .then function(承諾,如何將變量傳遞給 .then 函數)
      <i id='Ai12U'><tr id='Ai12U'><dt id='Ai12U'><q id='Ai12U'><span id='Ai12U'><b id='Ai12U'><form id='Ai12U'><ins id='Ai12U'></ins><ul id='Ai12U'></ul><sub id='Ai12U'></sub></form><legend id='Ai12U'></legend><bdo id='Ai12U'><pre id='Ai12U'><center id='Ai12U'></center></pre></bdo></b><th id='Ai12U'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Ai12U'><tfoot id='Ai12U'></tfoot><dl id='Ai12U'><fieldset id='Ai12U'></fieldset></dl></div>

          <tbody id='Ai12U'></tbody>
      1. <small id='Ai12U'></small><noframes id='Ai12U'>

        <tfoot id='Ai12U'></tfoot>

          <bdo id='Ai12U'></bdo><ul id='Ai12U'></ul>
        • <legend id='Ai12U'><style id='Ai12U'><dir id='Ai12U'><q id='Ai12U'></q></dir></style></legend>

              • 本文介紹了承諾,如何將變量傳遞給 .then 函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                您好,這是一個幫助我了解 Promises .then 如何返回工作的問題.問題是:如何將變量范圍限定為第二個 .then 鏈式函數?

                Hello this is a question to help me understand how Promises .then returns work. The question is: how can I scoped variables to the second .then chained function?

                這是一個 jsbin http://jsbin.com/xacuna/edit?js,output

                Here is a jsbin http://jsbin.com/xacuna/edit?js,output

                我可以訪問全局變量,然后將作用域變量傳遞給第一個,而不是之后.

                I can access the global variables, and pass in the scoped variables to the first then, but not after.

                  let innerReturnFunction = (res, myName) => {
                    /* this works */
                    console.log(`hi from inner name: ${myName}`)
                    return res
                  }
                
                 let getInnerFuncVariable = () => {
                   var myName = 'arturo'
                
                   return fetch('https://httpbin.org/get')
                    .then(function (res) {
                      myName = 'Bob'
                      return innerReturnFunction(res, myName);
                    })
                    .then(function (res, myName) {
                      /* doesn't work, how can I access myName */
                      console.log(`in first then ${res.url}, ${myName}`)
                    });
                 }
                
                getInnerFuncVariable().then(function(res, myName) {
                  /* how can I access myName */
                  console.log(`last called ${myName}`)
                })
                

                推薦答案

                當你使用 ES2015 - 簡單的解決方案使用 對象速記屬性名稱 和 對象解構

                as you are using ES2015 - easy solution uses object Shorthand property names and Object destructuring

                let innerReturnFunction = ({res, myName}) => {
                    /* this works */
                    console.log(`hi from inner name: ${myName}`);
                    return {res, myName}; // return an object
                }
                
                let getInnerFuncVariable = () => {
                    var myName = 'arturo';
                
                    return fetch('https://httpbin.org/get')
                        .then(function(res) {
                            myName = 'Bob'
                            return innerReturnFunction({res, myName});
                        })
                        .then(function({res, myName}) {
                            console.log(`in first then ${res.url}, ${myName}`);
                            return {res, myName};// ADD THIS!!
                        });
                }
                
                getInnerFuncVariable().then(function({res, myName}) {
                    console.log(`last called ${myName}`)
                })
                

                這篇關于承諾,如何將變量傳遞給 .then 函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)

                      <bdo id='3pkQU'></bdo><ul id='3pkQU'></ul>
                      <i id='3pkQU'><tr id='3pkQU'><dt id='3pkQU'><q id='3pkQU'><span id='3pkQU'><b id='3pkQU'><form id='3pkQU'><ins id='3pkQU'></ins><ul id='3pkQU'></ul><sub id='3pkQU'></sub></form><legend id='3pkQU'></legend><bdo id='3pkQU'><pre id='3pkQU'><center id='3pkQU'></center></pre></bdo></b><th id='3pkQU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3pkQU'><tfoot id='3pkQU'></tfoot><dl id='3pkQU'><fieldset id='3pkQU'></fieldset></dl></div>

                      <tfoot id='3pkQU'></tfoot>
                        <tbody id='3pkQU'></tbody>

                        1. <legend id='3pkQU'><style id='3pkQU'><dir id='3pkQU'><q id='3pkQU'></q></dir></style></legend>

                          <small id='3pkQU'></small><noframes id='3pkQU'>

                          主站蜘蛛池模板: 一区在线视频 | 日韩精品一区二区三区在线观看 | 久久亚洲国产精品 | 91精品国产乱码麻豆白嫩 | 国产精品国产a级 | 天堂av中文在线 | 亚洲一区欧美一区 | 国产精品免费一区二区三区四区 | 国产精品久久久久久久模特 | 中文字幕在线观看一区 | 狠狠操天天干 | 午夜精品久久久 | 国产日韩欧美一区二区在线播放 | 日韩视频国产 | 精品国产91乱码一区二区三区 | 国产成人黄色 | 视频一区二区中文字幕 | 国产午夜精品一区二区三区四区 | 国产原创在线观看 | 久久免费观看一级毛片 | 懂色av一区二区三区在线播放 | 国产精品久久久久久婷婷天堂 | 在线欧美亚洲 | 中文字幕一区二区三区四区 | 日本a∨精品中文字幕在线 亚洲91视频 | 国产美女在线看 | 日韩在线小视频 | 久久国产成人 | 欧美综合一区二区三区 | 亚洲精品18 | 嫩草91在线| 亚洲三级在线 | 一级做a毛片 | 午夜影院在线观看 | 91热在线 | 欧美三级不卡 | 精品国产乱码久久久久久丨区2区 | 日本又色又爽又黄的大片 | 精品在线一区二区 | 久草青青草 | 日韩精品视频在线免费观看 |