字符模板和全局函数

56 阅读1分钟

模板字符串函数

const name = 'smu'
const gender = true

function myTag(arge,name,gender) {
  return arge[0] + name + arge[1] + gender + arge[2]
}

const result = myTag`hey,${name} is a ${gender}.`

console.log(result);//hey,smu is a true.

全局函数

#函数可把字符串作为 URI 进行编码
encodeURI(uri)

#函数可对 encodeURI() 函数编码过的 URI 进行解码
decodeURI(uri)

#函数可把字符串作为 URI 组件进行编码
encodeURIComponent(uri)

#函数可对 encodeURIComponent() 函数编码的 URI 进行解码
decodeURIComponent(uri)

#函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串(对中文进行编码)
//该方法不会对 ASCII 字母和数字进行编码,也不会对下面这些 ASCII 标点符号进行编码: * @ - _ + . / 。其他所有的字符都会被转义序列替换
escape(string)

#函数可对通过 escape() 编码的字符串进行解码。
unescape(string)