Created
June 16, 2015 20:35
-
-
Save ekkis/2782982886a99628eca0 to your computer and use it in GitHub Desktop.
Javascript string prototypes
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 ret = this; | |
for (var i = 0; i < arguments.length; i++) { | |
var rex = RegExp("\\{" + i + "\\}", "g"); | |
ret = ret.replace(rex, arguments[i]); | |
} | |
return ret; | |
} | |
String.prototype.q = function() { | |
return "'" + this.replace("'", "''") + "'"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment