Last active
August 29, 2015 13:57
-
-
Save st98/9481111 to your computer and use it in GitHub Desktop.
Pythonのstr#formatもどき。
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
(function () { | |
var slice = [].slice; | |
String.prototype.format = function (/* ...args */) { | |
var args = slice.call(arguments); | |
var count = 0; | |
return this.replace(/{(\d+)?}/g, function (m, n) { | |
if (typeof n === 'undefined') { | |
return args[count++]; | |
} else { | |
return args[n]; | |
} | |
}); | |
}; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment