使用该
String.prototype.replace方法的另一种方法,将“替换”功能作为第二个参数:
String.prototype.format = function () { var i = 0, args = arguments; return this.replace(/{}/g, function () { return typeof args[i] != 'undefined' ? args[i++] : ''; });};var bar1 = 'foobar', bar2 = 'jumped', bar3 = 'dog';'The lazy {} {} over the {}'.format(bar3, bar2, bar1);// "The lazy dog jumped over the foobar"


