Convert a string to a template string

前端 未结 19 2172
轮回少年
轮回少年 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:11

    I made my own solution doing a type with a description as a function

    export class Foo {
    ...
    description?: Object;
    ...
    }
    
    let myFoo:Foo = {
    ...
      description: (a,b) => `Welcome ${a}, glad to see you like the ${b} section`.
    ...
    }
    

    and so doing:

    let myDescription = myFoo.description('Bar', 'bar');
    

提交回复
热议问题