I assume the best way to do this is quite obvious, simply reverse the situation given by the question. You just need to wrap the template literals in a function, and then you will delay evaluation until you pass in the desired params. It's that simple.
function evaluteTemplateLiteral(bar){
return `foo ${bar} baz`;
}
now if you wanted to get fancier, you could create this:
function evaluateGeneric(vals, fn){
return fn.apply(null, vals);
}
and you would use the above like so:
evaluateGeneric(['brown','fox','cholo'], function(){
return `the quick ${arguments[0]} fox ${arguments[1]}`;
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…