typescript 之 字符串特性

1、多行字符串(用  `xxx`  双撇号包裹字符串)

var string = `aaa
bbb
ccc`;

 

2、字符串模板(在多行字符串里面引入一个表达式去插入变量或者一个方法的调用)

var string = "aaa";
var getString = function(){
  return "aaa";
}
console.log(`hello ${string}`);  // "hello aaa"
console.log(`hello ${getString()}`);  // "hello aaa"

3、自动拆分字符串(当在用一个字符串模板去调用一个方法的时候,这个字符串模板里面表达式的值会自动赋给被调用方法中的参数)

function hello (template, name, age) {
  console.log(template);
  console.log(name);
  console.log(age);
}
var myName = "张三";
var getAge = function () {
  return 18;
}
hello`Hello, my name's ${myName}, i'm ${getAge()}`;
原文地址:https://www.cnblogs.com/joffe/p/7702585.html