Created
November 29, 2019 20:36
-
-
Save charly-palencia/aa41cd9fa5ae69d00e73438399adcf33 to your computer and use it in GitHub Desktop.
JS Template Literals: Tagged templates
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
| const styled; | |
| const myTag = (strings, ...args) => { | |
| const emojiFruits= { | |
| "bannana": "π", | |
| "pear": "π", | |
| "apple": "π", | |
| }; | |
| // input: ["Let's make some mix juice with ", ' in the ', '' ] | |
| const [str0, str1] = strings; | |
| // input: [ [ 'bannana', 'apple', 'pear' ] ] | |
| const [fruits] = args; | |
| const emojis = fruits.map(fruit => emojiFruits[fruit]).join(); | |
| // Concat Em All! | |
| return [str0, emojis, str1].join(""); | |
| }; | |
| const fruits = ["bannana", "apple", "pear"]; | |
| myTag`Let's make some mix juice with ${fruits}!!!` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment