我正在寻找一个很好的JavaScript等价的C/PHP printf()或C#/ Java程序员String.Format()(IFormatProvider对于.NET).
我的基本要求是现在有一千个数字分隔符格式,但处理许多组合(包括日期)的东西会很好.
我意识到Microsoft的Ajax库提供了一个版本String.Format(),但我们不希望该框架的整个开销.
Python有这个美丽的功能来解决这个问题:
bar1 = 'foobar'
bar2 = 'jumped'
bar3 = 'dog'
foo = 'The lazy ' + bar3 + ' ' + bar2 ' over the ' + bar1
# The lazy dog jumped over the foobar
Run Code Online (Sandbox Code Playgroud)
进入:
bar1 = 'foobar'
bar2 = 'jumped'
bar3 = 'dog'
foo = 'The lazy {} {} over the {}'.format(bar3, bar2, bar1)
# The lazy dog jumped over the foobar
Run Code Online (Sandbox Code Playgroud)
JavaScript有这样的功能吗?如果没有,我将如何创建一个遵循与Python实现相同的语法?