Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple tagged template functions
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
You can’t perform that action at this time.