Skip to content

Instantly share code, notes, and snippets.

@softwarespot
Last active September 30, 2015 06:15
Show Gist options
  • Save softwarespot/2e36ceb96ff73409ff9d to your computer and use it in GitHub Desktop.
Save softwarespot/2e36ceb96ff73409ff9d to your computer and use it in GitHub Desktop.
ES2015 tagged template strings
function valueToUpper(strings, ...values) {
// Set the values i.e. first and last name to upper-case
values[0] = values[0].toUpperCase();
values[1] = values[1].toUpperCase();
// Re-create the template
return `${strings[0]}${values[0]}${strings[1]}${values[1]}${strings[2]}`;
}
// Create first and last name variables
const firstName = 'Joe';
const lastName = 'Bloggs';
// Pass the template to a custom format function
const template = valueToUpper `Welcome ${firstName} ${lastName} to the site.`;
// Display the new template
console.log(template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment