Created
September 26, 2013 14:46
-
-
Save colthreepv/6715230 to your computer and use it in GitHub Desktop.
sprint-like function for javascript
This file contains 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
/** | |
* Thanks Raymond Powell | |
* http://stackoverflow.com/a/14640439/1071793 | |
*/ | |
String.prototype.format = function () { | |
var formatted = this, | |
prop, | |
regexp = new RegExp('\\{' + prop + '\\}', 'gi'); | |
for (prop in arguments[0]) { | |
formatted = formatted.replace(regexp, arguments[0][prop]); | |
} | |
return formatted; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment