Created
July 8, 2015 14:03
-
-
Save triblondon/5530fb06586a090ec67d to your computer and use it in GitHub Desktop.
Template strings tag function
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 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