Last active
August 29, 2015 14:10
-
-
Save bmeck/3307a80fab1cae8243cb to your computer and use it in GitHub Desktop.
simple tagged template functions
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
let tee = (a) => {console.log(String(a)); return a} | |
// our applicator | |
let $_ = (n) => { | |
let args = new Array(n); | |
for (let i = 1; i <= n; i++) { | |
args[i-1] = `$${i}` | |
} | |
return (raw, ...values) => | |
Function(...args.concat(tee('return ' + raw.reduce( | |
(src,str,i) => { | |
return src + values[i-1] + str | |
} | |
).trim()))); | |
} | |
let just_a_sec = $_(1)` | |
setTimeout($1, 1000) | |
` | |
just_a_sec((_)=> | |
alert('ok') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment