Skip to content

Instantly share code, notes, and snippets.

@triblondon
Created July 8, 2015 14:03
Show Gist options
  • Save triblondon/5530fb06586a090ec67d to your computer and use it in GitHub Desktop.
Save triblondon/5530fb06586a090ec67d to your computer and use it in GitHub Desktop.
Template strings tag function
function makeTagFunction(fn) {
return (literals, ...substitutions) => {
return literals.map((str, idx) => {
return str + ((idx in substitutions) ? fn(substitutions[idx]) : '');
}).join('');
}
}
let a = 5;
let b = 10;
function addOne(x) { return x+1; }
var f = makeTagFunction(addOne);
console.log(f`Testing ${a} and ${b}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment