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()}`;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM