Created
November 20, 2014 11:07
-
-
Save wangzuo/3bbaa158ee92b8073945 to your computer and use it in GitHub Desktop.
String.prototype.format
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
if(!String.prototype.format) { | |
String.prototype.format = function() { | |
var cnt = 0; | |
var args = arguments; | |
return this.replace(/(\%s)/g, function(match) { | |
var term = typeof args[cnt] !== 'undefined' ? args[cnt] : match; | |
cnt++; | |
return term; | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment