String.rawString.raw是一个模板字符串标签函数(如果不知道什么是标签函数,请点击?),它返回模板字符串的原始字符串。例如\n不会被当作换行符,而是两个普通字符\和n:console.log(String.raw`1\n2`);//1\n2通常我们不需要把它当作普通函数来调用,但是如果一定要当作普通函数来调用,注意传入参数的格式:(template:{raw:readonlystring[]|ArrayLike;},...substitutions:any[])=>stringString.raw第一个参数必须是具有raw属性的对象,属性值为字符数组或字符类数组,并且其余参数是插入的值。console.log(String.raw({raw:'abcd'},0,1,2));//a0b1c2d//34两次插值超出模板数组范围,将被忽略console.log(String.raw({raw:['a','b','c','d']},0,1,2,3,4));//a0b1c2dString.prototype.repeat函数类型:(count?:number)=>stringrepeat函数会根据传入的参数n返回一个将原字符串重复n次的新字符串,参数n默认为0。//当传入0或不传入参数时,原字符串重复0次,返回空字符串console.log('a'.repeat(0));//''console.log('a'.repeat(2));//'aa'String.prototype.startsWith,String.prototype.endsWith,String.prototype.includes函数类型:(queryString?:string,startPosition?:number)=>booleanstartsWith,endsWidthandincludes函数是ES6的新函数,用于检查字符串接收两个参数。第一个参数queryString是原始字符串中要查询的字符串,第二个参数startPostion是开始查询的位置。在includes和startsWith中,startPosition的默认值为0,而在endsWith中,startPostion默认为原始字符串的长度。console.log('abcde'.includes('a'));//true//改变起始位置console.log('abcde'.includes('a',1));//falseconsole.log('abcde'.startsWith('a'));//true//改变起始位置console.log('abcde'.startsWith('a',1));//falseconsole.log('abcde'.endsWith('a'));//false//改变起始位置console.log('abcde'.endsWith('a',1));//true需要注意的是,当待查字符串为参数queryString为空字符串''时,这三个函数的返回结果始终为true。console.log('abcde'.includes(''));//true//改变起始位置console.log('abcde'.includes('',1));//trueconsole.log('abcde'.startsWith(''));//true//改变起始位置console.log('abcde'.startsWith('',1));//trueconsole.log('abcde'.endsWith(''));//true//改变起始位置console.log('abcde'.endsWith('',1));//真的