Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created April 3, 2017 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/3dfb030cb6181af81062e5c780245f00 to your computer and use it in GitHub Desktop.
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?
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