Skip to content

Instantly share code, notes, and snippets.

@bmeck
Last active August 29, 2015 14:10
Show Gist options
  • Save bmeck/3307a80fab1cae8243cb to your computer and use it in GitHub Desktop.
Save bmeck/3307a80fab1cae8243cb to your computer and use it in GitHub Desktop.
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