Created
July 1, 2013 11:16
-
-
Save klarstil/5900031 to your computer and use it in GitHub Desktop.
Simple method which fills out the placeholders in a string
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
/** | |
* Formats a string and replaces the placeholders. | |
* | |
* @example format('<div class="%0"'>%1</div>, [value for %0], [value for %1], ...) | |
* | |
* @param {String} str | |
* @param {Mixed} | |
* @returns {String} | |
*/ | |
var format = function (str) { | |
for (var i = 1; i < arguments.length; i++) { | |
str = str.replace('%' + (i - 1), arguments[i]); | |
} | |
return str; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment