Last active
August 29, 2015 13:56
-
-
Save jarrodhroberson/8806794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Only add if it doesn't exist yet! | |
if (!String.prototype.format) { | |
String.prototype.format = function() { | |
var str = this.toString(); | |
if (!arguments.length) | |
return str; | |
var args = typeof arguments[0], | |
args = (("string" == args || "number" == args) ? arguments : arguments[0]); | |
for (arg in args) | |
str = str.replace(RegExp("\\{" + arg + "\\}", "gi"), args[arg]); | |
return str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage is :
results in
or
results in