Created
May 25, 2016 07:18
-
-
Save andineck/c691a7242eba25bf1c1913ca9d00721c to your computer and use it in GitHub Desktop.
assemble javascript template strings
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
// code from http://stackoverflow.com/questions/29771597/how-can-i-construct-a-template-string-from-a-regular-string | |
// + handling unlimited arguments | |
function assemble(literal, params) { | |
var args = [].slice.apply(arguments) | |
args.shift() | |
return new Function(args, "return `"+literal+"`") | |
} | |
var template = assemble("Hello, my name is ${name} ${surname}", "name", "surname") | |
template("Max", "Muster") // Hello, my name is Max Muster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
proper solution with resolving objects: https://www.npmjs.com/package/es6-template-strings