gpt4 book ai didi

javascript - 你能像 String.fromCharCode 一样使用 String.fromCodePoint 吗

转载 作者:可可西里 更新时间:2023-11-01 02:56:28 34 4
gpt4 key购买 nike

我仍在学习 JavaScript 并练习从键盘获取输入。我刚刚了解了 String.fromCodePoint 并且(对我而言)它似乎掌握了 String.fromCharCode 所做的一切。

String.fromCodePoint 是否被浏览器和设备广泛支持?如果是,它是否会使 String.fromCharCode 过时,或者您是否有理由使用 String.fromCharCode 而不是有时?

最佳答案

fromCharCode 还没有过时,但如果所有浏览器都支持它就会过时。但是 fromCharCode 是关于 twice as fast 的作为 fromCodePoint

  • String.fromCodePoint()Internet Explorer 和 Safari 不支持

  • String.fromCharCode()一直支持,速度加倍

  • 区别:

    Although most common Unicode values can be represented with one 16-bit number (as expected early on during JavaScript standardization) and fromCharCode() can be used to return a single character for the most common values (i.e., UCS-2 values which are the subset of UTF-16 with the most common characters), in order to deal with ALL legal Unicode values (up to 21 bits), fromCharCode() alone is inadequate. Since the higher code point characters use two (lower value) "surrogate" numbers to form a single character, String.fromCodePoint() (part of the ES6 draft) can be used to return such a pair and thus adequately represent these higher valued characters.

关于javascript - 你能像 String.fromCharCode 一样使用 String.fromCodePoint 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34680898/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com