Created
April 3, 2017 20:06
-
-
Save rlemon/3dfb030cb6181af81062e5c780245f00 to your computer and use it in GitHub Desktop.
tagged template literals fn.js or, what am I doing with my life?
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
function fn(v, ...args) { | |
const f = new Function([...args].map((_,i)=>`$${i}`), v.join('').split('|')[1]); | |
f.name = v[0][0]; // this does nothing. | |
return f.apply(null, args) | |
} | |
const b = fn`add ${2} ${2} ${3} | | |
let a = $0; | |
let b = $2; | |
return a + b; | |
`; | |
console.log(b); // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment