Here you can find the source of format()
String.prototype.format = function() { var s = this, i = arguments.length while (i--) { s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]) }// w w w. ja v a 2 s. c om return s }
String.prototype.format = function(){ var args = arguments; return this.replace(/\{(\d)\}/g, function(a,b){ return typeof args[b] != 'undefined' ? args[b] : a; });
var util = require('util'); String.prototype.format = function () { return util.format.apply(null, [ this.toString() ].concat(Array.prototype.slice.call(arguments))); };
String.prototype.format = function(){ var pattern = /\{\d+\}/g; var args = arguments; return this.replace(pattern, function(capture){ return args[capture.match(/\d+/)]; });
String.prototype.format = function() { var formatted = this; _.forEach(arguments, function(arg, i) { formatted = formatted.replace("{" + i + "}", arg); }); return formatted; };
'use strict'; String.prototype.format = function() { var formatted = this; for (var arg in arguments) { formatted = formatted.replace('{' + arg + '}', arguments[arg]); return formatted; };
String.prototype.format = function() { var formatted = this; for( var arg in arguments ) { formatted = formatted.replace("{" + arg + "}", arguments[arg]); return formatted; };
String.prototype.format = function() { var args = arguments; return this.replace(/{(\d+)}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number] : match ; }); }; ...
var util = require('util'); String.prototype.format = function() { var args = Array.prototype.slice.call(arguments); args.splice(0, 0, this.toString()); return util.format.apply(null, args); };
String.prototype.format = function() { var args = arguments; return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function(m, n) { if (m == "{{") return "{"; if (m == "}}") return "}"; return args[n]; }); };