var s = string.Format("this is a {0} test at {1}", "successful", DateTime.Now);
this is a successful test at 02/26/2010 13:51:11
String.format = String.prototype.format = function() { var string = this; var i = 0; if (typeof (this) == "function") { string = arguments[0]; i++; } for (; i < arguments.length; i++) string = string.replace(/\{\d+?\}/, arguments[i]); return string; }
"this is a {0} test at {1}".format("successful", new Date()); String.format("this is another {0} test at {1}", "successful", new Date());
تگها: javascript, prototype
Programming