Skip to content

Instantly share code, notes, and snippets.

@andineck

andineck/assemble.js

Created May 25, 2016
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@andineck andineck commented May 25, 2016

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