Skip to content

Instantly share code, notes, and snippets.

@andineck
Created May 25, 2016 07:18
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 andineck/c691a7242eba25bf1c1913ca9d00721c to your computer and use it in GitHub Desktop.
Save andineck/c691a7242eba25bf1c1913ca9d00721c to your computer and use it in GitHub Desktop.
assemble javascript template strings
// 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
@andineck
Copy link
Author

proper solution with resolving objects: https://www.npmjs.com/package/es6-template-strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment