Skip to content

Instantly share code, notes, and snippets.

@travisj
Created April 22, 2010 03:10
Show Gist options
  • Save travisj/374760 to your computer and use it in GitHub Desktop.
Save travisj/374760 to your computer and use it in GitHub Desktop.
String.prototype.template = function (o) {
if (!o) {
return this.toString();
}
return this.replace(/{([^{}]*)}/g,
function (a, b) {
var r = o[b];
if (r === null) {
return '';
} else {
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment