Here you can find the source of format()
/**//from w w w .j a v a 2 s .c om * Created by gabello on 10/7/2014. */ String.format = function() { "use strict" // The string containing the format items (e.g. "{0}") // will and always has to be the first argument. var theString = arguments[0]; // start with the second argument (i = 1) for (var i = 1; i < arguments.length; i++) { // "gm" = RegEx options for Global search (more than one instance) // and for Multiline search var regEx = new RegExp("\\{" + (i - 1) + "\\}", "gm"); theString = theString.replace(regEx, arguments[i]); } return theString; };
String.prototype.format = function () { var args = arguments; return this.replace(/\{(\d+)\}/g, function (m, i, o, n) { return args[i]; }); };
String.prototype.format = function () { var i = 0, args = arguments; return this.replace(/{(.*?)}/g, function (match, tagInner) { replacement = typeof args[i] != 'undefined' ? args[i++] : ''; if(tagInner == "") { return replacement; } else { var match = tagInner.match(/^:.(\d+)f$/); if(match) { ...
String.prototype.format = function() { var s = this, i = arguments.length; while (i--) { s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); return s; };
String.prototype.format = function () { var args = arguments; var input = this; var output = ""; if (input.length > 0) { if (args[0] === undefined || args[0] === null) { output = "string without any arguments"; else { ...
String.prototype.format = function() { var stringToReturn = this.toString(); for(var i = 0; i < arguments.length; i++) { var regex = new RegExp("\\{" + i + "\\}", "g"); stringToReturn = stringToReturn.replace(regex, arguments[i]); return stringToReturn; };
'use strict'; String.prototype.format = function () { var content = this; for (var i = 0; i < arguments.length; i++) { var replacement = '{' + i + '}'; content = content.replace(replacement, arguments[i]); return content; }; ...
String.prototype.format = function (...args) { return this.replace(/\{(\d+)\}/g, function (m, i) { return args[i] })
String.prototype.format = function(arg) { var argLen, args, repFn, str; repFn = void 0; str = this; if (typeof arg === "object") { repFn = function(a, b) { if (arg[b]) { return arg[b]; } else { ...
var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { if(args[key]!=undefined){ var reg = new RegExp("({" + key + "})", "g"); result = result.replace(reg, args[key]); else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] != undefined) { var reg = new RegExp("({[" + i + "]})", "g"); result = result.replace(reg, arguments[i]); return result; };