Skip to content

Instantly share code, notes, and snippets.

@0i0
Created December 25, 2011 22:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0i0/1519811 to your computer and use it in GitHub Desktop.
Save 0i0/1519811 to your computer and use it in GitHub Desktop.
javascript snippets
function getCookie(key){
var regEx = new RegExp(key+"=([^;]*)","g");
return regEx.exec(document.cookie)[1]
}
String.prototype.format = function () {
var args = arguments;
return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function (curlyBrack, index) {
return ((curlyBrack == "{{") ? "{" : ((curlyBrack == "}}") ? "}" : args[index]));
});
};
"{0}{1}".format("{1}", "{0}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment