Artificial intelligent assistant

変数からtemplate stringsを生成したい ECMAScripttagged template template stringstemplate literals var name = "user input here"; var str = `Hello, ${name}!`; tagged template strings evalFunction var name = "user input here"; var template = "Hello, ${name}"; var tagfunc = function(){ ... }; var str = eval( "tagfunc`" + template + "`" ); `template` `template`evalXSSContent-Security-Policyeval

`eval`



`eval` DSL


//
function apply_tpl(tpl, dict){
Object.keys(dict).forEach(function(k) {tpl = tpl.replace(new RegExp('\\${' + k + '}','g'), dict[k]);})
return tpl;
}

// :
apply_tpl("Hello, ${name}", { name: "Arthur"} )
// => Hello, Arthur.

// : ()
var value1 = "Cathy"

apply_tpl("Hello, ${value1}", this)
// => "Hello, Cathy"

apply_tpl("Hello, ${value2}", this)
// => "Hello, ${value2}"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 22b1c169fbeab8b40b08ce5fb9d13a60