Created
January 25, 2019 02:06
-
-
Save alvaaz/251022617a48d0ac056868eebcc1abe5 to your computer and use it in GitHub Desktop.
Tagged template
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 highlight(strings, ...values){ | |
| let str = ''; | |
| strings.forEach((string, i) => { | |
| str += `${string} <span class="hl">${values[i] || ''}</span>`; | |
| }); | |
| return str; | |
| } | |
| const name = 'Snickers'; | |
| const age = 100; | |
| const sentence = hightlight`My dog's name is ${name} and he is ${age} years old`; | |
| document.body.innerHTML = sentence; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment