Use of String.Format in JavaScript?

后端 未结 19 2036
逝去的感伤
逝去的感伤 2020-12-04 07:59

This is driving me nuts. I believe I asked this exact same question, but I can\'t find it any more (I used Stack Overflow search, Google Search, manually searched my po

19条回答
  •  -上瘾入骨i
    2020-12-04 08:35

    Use a template literal in ECMAScript 6:

    var customer = { name: "Foo" }
    var card = { amount: 7, product: "Bar", unitprice: 42 }
    var message = `Hello ${customer.name},
                   want to buy ${card.amount} ${card.product} for
                   a total of ${card.amount * card.unitprice} bucks?`
    

提交回复
热议问题