Last active
September 30, 2015 06:15
-
-
Save softwarespot/2e36ceb96ff73409ff9d to your computer and use it in GitHub Desktop.
ES2015 tagged template strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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