Skip to content

Instantly share code, notes, and snippets.

@afonsomatos
Last active August 29, 2015 14:23
Show Gist options
  • Save afonsomatos/57b23716bf4e12203534 to your computer and use it in GitHub Desktop.
Save afonsomatos/57b23716bf4e12203534 to your computer and use it in GitHub Desktop.
Overview of template strings and tagged templates on ES6
// Template strings
`Hello my name is ${firstName} ${lastName}`
// Mult-line
`This is a multi-line
string that appears
to be very cool perhaps
it is.`
// Tagged template
tagFunction`Hello\n ${firstName} ${lastName}`
// Implement tagFunction
function tagFunction(strings, ...values) {
strings; // ['Hello', ' ']
strings[0]; // 'Hello
// '
strings.raw[0]; // 'Hello\n'
values; // [firstName, lastName]
return strings.join('');
}
// How the tagfunction is called
tagFunction(['Hello ', ' '], firstName, lastName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment