pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="j0vnmlz" 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="rzv35dv" 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="eh5bidv" 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>
                            主站蜘蛛池模板: 英思科GTD-3000EX(美国英思科气体检测仪MX4MX6)百科-北京嘉华众信科技有限公司 | 通信天线厂家_室分八木天线_对数周期天线_天线加工厂_林创天线源头厂家 | 消电检公司,消电检价格,北京消电检报告-北京设施检测公司-亿杰(北京)消防工程有限公司 | 螺旋压榨机-刮泥机-潜水搅拌机-电动泥斗-潜水推流器-南京格林兰环保设备有限公司 | 彼得逊采泥器-定深式采泥器-电动土壤采样器-土壤样品风干机-常州索奥仪器制造有限公司 | 长春网站建设,五合一网站设计制作,免费优化推广-长春网站建设 | 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 深圳希玛林顺潮眼科医院(官网)│深圳眼科医院│医保定点│香港希玛林顺潮眼科中心连锁品牌 | 真空泵厂家_真空泵机组_水环泵_旋片泵_罗茨泵_耐腐蚀防爆_中德制泵 | 温州富欧金属封头-不锈钢封头厂家 | 重庆LED显示屏_显示屏安装公司_重庆LED显示屏批发-彩光科技公司 重庆钣金加工厂家首页-专业定做监控电视墙_操作台 | 消泡剂_水处理消泡剂_切削液消泡剂_涂料消泡剂_有机硅消泡剂_广州中万新材料生产厂家 | 刘秘书_你身边专业的工作范文写作小秘书| 电梯乘运质量测试仪_电梯安全评估测试仪-武汉懿之刻 | 碳化硅,氮化硅,冰晶石,绢云母,氟化铝,白刚玉,棕刚玉,石墨,铝粉,铁粉,金属硅粉,金属铝粉,氧化铝粉,硅微粉,蓝晶石,红柱石,莫来石,粉煤灰,三聚磷酸钠,六偏磷酸钠,硫酸镁-皓泉新材料 | LZ-373测厚仪-华瑞VOC气体检测仪-个人有毒气体检测仪-厂家-深圳市深博瑞仪器仪表有限公司 | 定制/定做冲锋衣厂家/公司-订做/订制冲锋衣价格/费用-北京圣达信 | 智慧水务|智慧供排水利信息化|水厂软硬件系统-上海敢创 | 欧必特空气能-商用空气能热水工程,空气能热水器,超低温空气源热泵生产厂家-湖南欧必特空气能公司 | 上海办公室设计_办公楼,写字楼装修_办公室装修公司-匠御设计 | elisa试剂盒-PCR试剂盒「上海谷研实业有限公司」 | 至顶网| 西安文都考研官网_西安考研辅导班_考研培训机构_西安在职考研培训 | 水压力传感器_数字压力传感器|佛山一众传感仪器有限公司|首页 | 无菌水质袋-NASCO食品无菌袋-Whirl-Pak无菌采样袋-深圳市慧普德贸易有限公司 | 窖井盖锯圆机_锯圆机金刚石锯片-无锡茂达金刚石有限公司 | PCB接线端子_栅板式端子_线路板连接器_端子排生产厂家-置恒电气 喷码机,激光喷码打码机,鸡蛋打码机,手持打码机,自动喷码机,一物一码防伪溯源-恒欣瑞达有限公司 假肢-假肢价格-假肢厂家-河南假肢-郑州市力康假肢矫形器有限公司 | 宝鸡市人民医院| 奥因-光触媒除甲醛公司-除甲醛加盟公司十大品牌 | 丝印油墨_水性油墨_环保油墨油漆厂家_37国际化工 | 合肥废气治理设备_安徽除尘设备_工业废气处理设备厂家-盈凯环保 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 西安文都考研官网_西安考研辅导班_考研培训机构_西安在职考研培训 | 卫生纸复卷机|抽纸机|卫生纸加工设备|做卫生纸机器|小型卫生纸加工需要什么设备|卫生纸机器设备多少钱一台|许昌恒源纸品机械有限公司 | 网站seo优化_seo云优化_搜索引擎seo_启新网络服务中心 | 网带通过式抛丸机,,网带式打砂机,吊钩式,抛丸机,中山抛丸机生产厂家,江门抛丸机,佛山吊钩式,东莞抛丸机,中山市泰达自动化设备有限公司 | 联系我们老街华纳娱乐公司官网19989979996(客服) | 合肥通道闸-安徽车牌识别-人脸识别系统厂家-安徽熵控智能技术有限公司 | 干式变压器厂_干式变压器厂家_scb11/scb13/scb10/scb14/scb18干式变压器生产厂家-山东科锐变压器有限公司 | 818手游网_提供当下热门APP手游_最新手机游戏下载 | 电杆荷载挠度测试仪-电杆荷载位移-管桩测试仪-北京绿野创能机电设备有限公司 | 焊接烟尘净化器__焊烟除尘设备_打磨工作台_喷漆废气治理设备 -催化燃烧设备 _天津路博蓝天环保科技有限公司 |