【发布时间】:2011-06-25 20:17:02
【问题描述】:
Python 有一个漂亮的函数来转这个:
bar1 = 'foobar'
bar2 = 'jumped'
bar3 = 'dog'
foo = 'The lazy ' + bar3 + ' ' + bar2 ' over the ' + bar1
# The lazy dog jumped over the foobar
进入这个:
bar1 = 'foobar'
bar2 = 'jumped'
bar3 = 'dog'
foo = 'The lazy {} {} over the {}'.format(bar3, bar2, bar1)
# The lazy dog jumped over the foobar
JavaScript有这样的功能吗?如果不是,我将如何创建一个遵循与 Python 实现相同的语法?
【问题讨论】:
-
查看这个帖子以获得解决方案:stackoverflow.com/questions/610406/…
-
我总是在我的许多网站中使用 jQuery,所以它不会受到伤害。 JS 是否允许您对字符串对象进行子类化或添加函数?
-
JavaScript 是一种基于原型的语言。您可以通过增强其通用原型来扩展一个类型的所有对象。
-
prototype是该语言的一个特性。 prototypejs 库是完全独立的。
标签: javascript python format