作者:
oopFoo (3d)
2018-09-04 15:07:04https://stackoverflow.com/questions/30003353/can-es6-template-literals-be-substituted-at-runtime-or-reused
function fillTemplate(templateString,templateVars) {
return new Function(`return \`${templateString}\`;`).call(templateVars);
}
因為需要做多國語言(前端做),找類似printf功能來置換value。
有看到,但都不滿意,因為想用es6 template literal來做。
問題是怎麼用string variable來當做template literal的置換?
真的有神人po出解決方案。很久沒這麼開心了,這行程式碼,看了兩三遍才看懂。
心得:
趕快用es6吧,寫程式真的開心很多。