javascript中的String.fromCharCode(十进制值)是否也支持扩展字符

javascript中的String.fromCharCode(十进制值)是否也支持扩展字符,javascript,string,Javascript,String,我正在使用函数String.fromCharCode(十进制值),并将十进制值传递给它 就英文字符而言,它工作得很好,但当我尝试对日语字符进行同样的解码时,它给了我一些arbit字符 有谁能告诉我它是字符串。fromCharCode(十进制值)支持扩展字符。不,它不支持使用两个代理的字符。具有用于处理此问题的实用程序功能: // String.fromCharCode() alone cannot get the character at such a high code point // Th

我正在使用函数String.fromCharCode(十进制值),并将十进制值传递给它

就英文字符而言,它工作得很好,但当我尝试对日语字符进行同样的解码时,它给了我一些arbit字符


有谁能告诉我它是字符串。fromCharCode(十进制值)支持扩展字符。

不,它不支持使用两个代理的字符。具有用于处理此问题的实用程序功能:

// String.fromCharCode() alone cannot get the character at such a high code point
// The following, on the other hand, can return a 4-byte character as well as the 
//   usual 2-byte ones (i.e., it can return a single character which actually has 
//   a string length of 2 instead of 1!)
alert(fixedFromCharCode(0x2F804)); // or 194564 in decimal

function fixedFromCharCode (codePt) {
    if (codePt > 0xFFFF) {
        codePt -= 0x10000;
        return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 +
(codePt & 0x3FF));
    }
    else {
        return String.fromCharCode(codePt);
    }
}