Created
May 2, 2012 12:49
-
-
Save daGrevis/2576324 to your computer and use it in GitHub Desktop.
String format in 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.prototype.format = function () { | |
| var g = this.toString(); | |
| if (!arguments.length) return g; | |
| var c = "string" == typeof arguments[0] ? arguments : arguments[0], | |
| e; | |
| for (e in c) g = g.replace(RegExp("\\{" + e + "\\}", "gi"), c[e]); | |
| return g | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment