Skip to content

Instantly share code, notes, and snippets.



Created May 25, 2016
What would you like to do?
assemble javascript template strings
// code from
// + handling unlimited arguments
function assemble(literal, params) {
var args = [].slice.apply(arguments)
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

This comment has been minimized.

Copy link
Owner Author

@andineck andineck commented May 25, 2016

proper solution with resolving objects:

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