Created
December 13, 2010 15:58
-
-
Save atzkey/739138 to your computer and use it in GitHub Desktop.
String.format extension for JavaScript
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
/* | |
String.format extension for JavaScript | |
Next line should give you an idea how to use it: | |
"{1}, {0}!".format("world", "Hello"); | |
*/ | |
String.prototype.format = function() { | |
var formatted = this; | |
for (arg in arguments) { | |
formatted = formatted.replace("{" + arg + "}", arguments[arg]); | |
} | |
return formatted; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment