Skip to content

Instantly share code, notes, and snippets.

@ekkis
Created June 16, 2015 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekkis/2782982886a99628eca0 to your computer and use it in GitHub Desktop.
Save ekkis/2782982886a99628eca0 to your computer and use it in GitHub Desktop.
Javascript string prototypes
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