JavaScript equivalent of Python's format() function?
问题 Python has this beautiful function to turn this: bar1 = 'foobar' bar2 = 'jumped' bar3 = 'dog' foo = 'The lazy ' + bar3 + ' ' + bar2 ' over the ' + bar1 # The lazy dog jumped over the foobar Into this: bar1 = 'foobar' bar2 = 'jumped' bar3 = 'dog' foo = 'The lazy {} {} over the {}'.format(bar3, bar2, bar1) # The lazy dog jumped over the foobar Does JavaScript have such a function? If not, how would I create one which follows the same syntax as Python's implementation? 回答1: Another approach,