String.prototype.format = function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(g0, g1) { return args[+g1]; }); } "hello {0},{0}'s age is {1}".format("tom",12)