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

  • <tfoot id='PSeZL'></tfoot><legend id='PSeZL'><style id='PSeZL'><dir id='PSeZL'><q id='PSeZL'></q></dir></style></legend>
      1. <small id='PSeZL'></small><noframes id='PSeZL'>

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

        Javascript 等價于 python 的 .format()

        Javascript equivalent to python#39;s .format()(Javascript 等價于 python 的 .format())

              <tbody id='09qwz'></tbody>
          1. <legend id='09qwz'><style id='09qwz'><dir id='09qwz'><q id='09qwz'></q></dir></style></legend>
              <tfoot id='09qwz'></tfoot>

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

                <bdo id='09qwz'></bdo><ul id='09qwz'></ul>
                • <small id='09qwz'></small><noframes id='09qwz'>

                • 本文介紹了Javascript 等價于 python 的 .format()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我想要一個模仿 python .format() 函數的 javascript 函數

                  I would like a javascript function that mimics the python .format() function that works like

                  .format(*args, **kwargs)
                  

                  上一個問題為 '.format(*args) 提供了一個可能(但不完整)的解決方案

                  A previous question gives a possible (but not complete) solution for '.format(*args)

                  JavaScript 等效于 printf/string.format

                  我希望能夠做到

                  "hello {} and {}".format("you", "bob"
                  ==> hello you and bob
                  
                  "hello {0} and {1}".format("you", "bob")
                  ==> hello you and bob
                  
                  "hello {0} and {1} and {a}".format("you", "bob",a="mary")
                  ==> hello you and bob and mary
                  
                  "hello {0} and {1} and {a} and {2}".format("you", "bob","jill",a="mary")
                  ==> hello you and bob and mary and jill
                  

                  我意識到這是一項艱巨的任務,但也許在某個地方有一個完整(或至少部分)的解決方案,其中也包括關鍵字參數.

                  I realize that's a tall order, but maybe somewhere out there is a complete (or at least partial) solution that includes keyword arguments as well.

                  哦,我聽說 AJAX 和 JQuery 可能有這方面的方法,但我希望能夠在沒有所有開銷的情況下做到這一點.

                  Oh, and I hear AJAX and JQuery possibly have methods for this, but I would like to be able to do it without all that overhead.

                  特別是,我希望能夠將它與 google doc 的腳本一起使用.

                  In particular, I would like to be able to use it with a script for a google doc.

                  謝謝

                  推薦答案

                  更新:如果您使用的是 ES6,模板字符串的工作方式與 String.format 非常相似:https://developers.google.com/web/updates/2015/01/ES6-Template-字符串

                  UPDATE: If you're using ES6, template strings work very similarly to String.format: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings

                  如果不是,以下適用于上述所有情況,其語法與 python 的 String.format 方法非常相似.下面是測試用例.

                  If not, the below works for all the cases above, with a very similar syntax to python's String.format method. Test cases below.

                  String.prototype.format = function() {
                    var args = arguments;
                    this.unkeyed_index = 0;
                    return this.replace(/{(w*)}/g, function(match, key) { 
                      if (key === '') {
                        key = this.unkeyed_index;
                        this.unkeyed_index++
                      }
                      if (key == +key) {
                        return args[key] !== 'undefined'
                        ? args[key]
                        : match;
                      } else {
                        for (var i = 0; i < args.length; i++) {
                          if (typeof args[i] === 'object' && typeof args[i][key] !== 'undefined') {
                            return args[i][key];
                          }
                        }
                        return match;
                      }
                    }.bind(this));
                  };
                  
                  // Run some tests
                  $('#tests')
                    .append(
                      "hello {} and {}<br />".format("you", "bob")
                    )
                    .append(
                      "hello {0} and {1}<br />".format("you", "bob")
                    )
                    .append(
                      "hello {0} and {1} and {a}<br />".format("you", "bob", {a:"mary"})
                    )
                    .append(
                      "hello {0} and {1} and {a} and {2}<br />".format("you", "bob", "jill", {a:"mary"})
                    );

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <div id="tests"></div>

                  這篇關于Javascript 等價于 python 的 .format()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                  Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                  Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                  How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                  Detect FLASH plugin crashes(檢測 FLASH 插件崩潰)
                  • <bdo id='YbAPp'></bdo><ul id='YbAPp'></ul>
                        <tfoot id='YbAPp'></tfoot>
                        <i id='YbAPp'><tr id='YbAPp'><dt id='YbAPp'><q id='YbAPp'><span id='YbAPp'><b id='YbAPp'><form id='YbAPp'><ins id='YbAPp'></ins><ul id='YbAPp'></ul><sub id='YbAPp'></sub></form><legend id='YbAPp'></legend><bdo id='YbAPp'><pre id='YbAPp'><center id='YbAPp'></center></pre></bdo></b><th id='YbAPp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YbAPp'><tfoot id='YbAPp'></tfoot><dl id='YbAPp'><fieldset id='YbAPp'></fieldset></dl></div>

                        <legend id='YbAPp'><style id='YbAPp'><dir id='YbAPp'><q id='YbAPp'></q></dir></style></legend>

                            <small id='YbAPp'></small><noframes id='YbAPp'>

                              <tbody id='YbAPp'></tbody>
                            主站蜘蛛池模板: 日韩中文字幕 | 亚洲第一黄色网 | 久久专区 | 国产在线永久免费 | 在线观看国产视频 | av中文字幕在线播放 | 国产美女一区二区 | 日日摸日日碰夜夜爽2015电影 | 亚洲成人中文字幕 | 欧美国产91 | 成人小视频在线观看 | 亚洲精品视频在线观看免费 | 亚洲a视频 | 日韩一区不卡 | 午夜精品一区二区三区在线视频 | 69福利影院| 东京久久 | 精品久久久久久 | 久久久久网站 | av在线播放国产 | 久久国产精品久久久久久久久久 | 一区二区电影 | 日本在线视频一区二区 | 日本不卡一区 | 日韩精品1区2区 | 国产资源在线观看 | pacopacomama在线| 亚州精品成人 | 最新中文字幕久久 | www在线| 黄色一级视频 | 欧美一级视频在线观看 | 在线一区二区三区 | 嫩呦国产一区二区三区av | 国产精品一区二区免费 | 97免费视频在线观看 | 欧美男男videos| 精品视频在线观看 | 国产精品久久久久久久久久 | 免费精品 | 亚洲精品视频在线播放 |