Skip to content

Instantly share code, notes, and snippets.

@jdfm
Last active January 12, 2016 01:12
Show Gist options
  • Save jdfm/f951c596ec5581f85d6f to your computer and use it in GitHub Desktop.
Save jdfm/f951c596ec5581f85d6f to your computer and use it in GitHub Desktop.
simple templates
/**
* Use a simple object to create your html with variables
* and whatever code you need to build it up.
*
* You can take advantage of type coercion here to
* end up with the final strings.
*/
var template = {
placeholder1: undefined,
placeholder2: undefined,
toString: function(){
return '' +
'<p>' + this.placeholder1 + '</p>' +
'<span>' +
'<em>' + this.placeholder2 + '</em>' +
'</span>' +
'';
}
};
template.placeholder1 = 'This is a paragraph!';
template.placeholder2 = 'This is emphasized text!';
console.log('constructor-casting', String(template));
console.log('stringification', '' + template);
console.log('method-calling', template.toString());
console.log(template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment