JavaScript equivalent of Python's format() function?

前端 未结 17 1979
慢半拍i
慢半拍i 2020-12-13 08:42

Python has this beautiful function to turn this:

bar1 = \'foobar\'
bar2 = \'jumped\'
bar3 = \'dog\'

foo = \'The lazy \' + bar3 + \' \' + bar2 \' over the \'         


        
17条回答
  •  醉梦人生
    2020-12-13 09:13

    In the file

    https://github.com/BruceSherwood/glowscript/blob/master/lib/glow/api_misc.js

    is a function String.prototype.format = function(args) that fully implements the Python string.format() function, not limited simply to handling character strings.

提交回复
热议问题