Here you can find the source of format(args)
String.prototype.format = function (args) { var newStr = this; for (var key in args) { newStr = newStr.replace(new RegExp("{" + key + "}","g"), args[key]); }//from ww w.j a v a 2s .c om return newStr; };
'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; };
String.prototype.format = function (args) { var newStr = this; for (var key in args) { newStr = newStr.replace('{' + key + '}', args[key]); return newStr;
String.prototype.format = function(args) { return this.replace(/{(\d+)}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number] : match ; }); };
String.prototype.format = function (args) { var regex = /{-?[0-9]+}/g; var str = this; return str.replace(regex, function(item) { var intVal = parseInt(item.substring(1, item.length - 1)); var replace; if (intVal >= 0) { replace = args[intVal]; } else { ...
String.prototype.format = function (args) { var result = this; var reg; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { if (args[key] != undefined) { reg = new RegExp("({" + key + "})", "g"); result = result.replace(reg, args[key]); ...
String.prototype.format = function(args){ var this_string = ''; for (var char_pos = 0; char_pos < this.length; char_pos++) { this_string = this_string + this[char_pos]; for (var key in args) { var string_key = '{' + key + '}'; this_string = this_string.replace(new RegExp(string_key, 'g'), args[key]); return this_string; };