Skip to content

静态方法

fromCharCode()

TIP

静态方法返回由指定的 UTF-16 码元序列创建的字符串

javascript
console.log(String.fromCharCode(189, 43, 190, 61));
// Expected output: "½+¾="

fromCodePoint()

TIP

静态方法将根据指定的码位序列返回一个字符串

javascript
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2f804));
// Expected output: "☃★♲你"

raw()

TIP

静态方法是模板字符串的标签函数。它的作用类似于 Python 中的 r 前缀或 C# 中用于字符串字面量的 @ 前缀。它用于获取模板字符串的原始字符串形式——即,替换表达式(例如 ${foo})会被替换处理,但转义序列(例如 \n)不会被处理

javascript
// Create a variable that uses a Windows
// path without escaping the backslashes:
const filePath = String.raw`C:\Development\profile\aboutme.html`;

console.log(`The file was uploaded from: ${filePath}`);
// Expected output: "The file was uploaded from: C:\Development\profile\aboutme.html"