Last active
August 29, 2015 14:23
-
-
Save afonsomatos/57b23716bf4e12203534 to your computer and use it in GitHub Desktop.
Overview of template strings and tagged templates on ES6
This file contains 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
// 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