Convert a string to a template string

前端 未结 19 2146
轮回少年
轮回少年 2020-11-22 08:30

Is it possible to create a template string as a usual string

let a=\"b:${b}\";

an then convert it into a template string

le         


        
19条回答
  •  盖世英雄少女心
    2020-11-22 09:21

    As your template string must get reference to the b variable dynamicly (in runtime), so the answer is: NO, it impossible to do without dynamic code generation.

    But with eval it's pretty simple:

    let tpl = eval('`'+a+'`');
    

提交回复
热议问题