Here you can find the source of format(args)
// http://stackoverflow.com/a/6420040 String.prototype.format = function (args) { var newStr = this; for (var key in args) { newStr = newStr.replace('{' + key + '}', args[key]); }/*from ww w.java2 s. c o m*/ return newStr; }
String.prototype.format = function(args) { 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;
function valPhone(phoneNumber) { if (!/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(phoneNumber)) { return false; } else { return true; String.prototype.format = function(args) { if (arguments.length>0) { ...
String.prototype.format = function (args) { var str = this; return str.replace(String.prototype.format.regex, function (item) { var intVal = parseInt(item.substring(1, item.length - 1)); var replace; if (intVal >= 0) { replace = args[intVal]; } else if (intVal === -1) { replace = "{"; ...
'use strict'; String.prototype.format = function (args) { if (arguments.length>0) { var result = this; console.log(this) if (arguments.length ==1 && typeof(args)=="object") { for(var key in args){ var reg = new RegExp ("({"+key+"})","g"); result = result.replace(reg,args[key]); ...
String.prototype.format = function(args) var result = this; if (arguments.length > 0) var reg; if (arguments.length == 1 && typeof(args) == "object") for (var key in args) ...
String.prototype.format = function(args, index) { return this.replace(/{(\w+)}/g, function(match, number) { return typeof args[index[number]] != 'undefined' ? args[index[number]] : match ; }); };
String.prototype.format = function (ctx) { return this.replace(/\$\{([\w\.]+)\}/g, function(all, varname) { var keys = varname.split('.'); var val = null; for (var i = 0, len = keys.length; i < len; i++) { val = ctx[keys[i]]; return val; }); ...
String.prototype.format = function(data) { return this.replace(/{(.+?)}/g, function(match, name) { return data[name] || match; }); };
String.prototype.format = function(dict) { var result = this; if(typeof(dict) === "object") { Object.keys(dict).forEach(function(key) { result = result.replace("{" + key + "}", dict[key]); }); return result; var args = []; ...