Function('a', 'b', 'a = String(a), b = String(b); return `${a}, ${b}!`')('hello', 'world')
eval isn't evil, only some of its users are.
16.12.2014, 14:48, "Niloy Mondal" <[email protected]>:
Can this be considered for a feature request? Provision in the language to dynamically construct template strings and interpolate them.,On Tue, Dec 16, 2014 at 4:48 PM, Andrea Giammarchi <[email protected]> wrote:irony ... I think you would need to evaluate the template string inline in order to interpolate its result ...ORyou just go for this method which also works down to ES3 engine:RegardsOn Tue, Dec 16, 2014 at 10:01 AM, Niloy Mondal <[email protected]> wrote:_______________________________________________Thanks, this would work.How can I construct a template string dynamically? Like reading the template from a file/database and then interpolate it.On Tue, Dec 16, 2014 at 2:29 PM, Claude Pache <[email protected]> wrote:Le 16 déc. 2014 à 09:27, Niloy Mondal <[email protected]> a écrit :I want to define a template string using backquotes in a different file and then have it interpolated with actual values in a different file. How can I do it?Just enclose it in a function:```_javascript_function foo(a) {return `some template ${a}`}foo("bar") // will evaluate `some template ${"bar"}````—Claude
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

