Beace Lee

Beace Blog

Written by Beace Lee who lives and works in China building useful things. You should follow him on Twitter

ECMAScript 2015 Features-c03-string-tpl

February 21, 2017

ECMAScript 2015 Features

Template Strings

字符串模板是用来构建字符串,并且可以在字符串中添加变量、表达式的语法糖。写法与Scala Playframework中的字符串拼接及其相似。

特点

  • 方便的拼接字符串
  • 提供字符串中添加变量、表达式等

写法

const GREETING = "Hello";

let sayHello = `${GREETING}, baby!`
let sayTime = `${GREETING}, the time is ${Date.now()}`
console.log(sayHello); // Hello, baby
console.log(sayTime);  // Hello, the time is Fri Feb 17 2017 13:38:49 GMT+0800 (CST)

Scala

Scala Playframework中的字符串拼接

val str = s"fasf${fda}"