你可以像String.fromCharCode一样使用String.fromCodePoint吗? [英] Can you use String.fromCodePoint just like String.fromCharCode

查看:209
本文介绍了你可以像String.fromCharCode一样使用String.fromCodePoint吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还在学习JavaScript并练习从键盘输入。我刚刚了解了 String.fromCodePoint ,似乎(对我来说)拿起 String.fromCharCode 所做的一切。

I'm still learning JavaScript and practicing with getting input from a keyboard. I just learned about String.fromCodePoint and it seems (to me) to pick up everything that String.fromCharCode does.

String.fromCodePoint 是否受到浏览器和设备的广泛支持?若然,它是否为 String.fromCharCode 已过时,或者您有时会使用 String.fromCharCode 吗?

Is String.fromCodePoint supported widespread by browsers and devices and if so, does it make String.fromCharCode obsolete, or is there a reason you would use String.fromCharCode instead sometimes?

推荐答案

fromCharCode 尚未过时,但如果所有浏览器都支持它。但是关于快两倍 as fromCodePoint

fromCharCode is not obsolete yet, but it would be if it would be supported by all Browsers. However fromCharCode is about twice as fast as fromCodePoint

  • String.fromCodePoint() Not supported by Internet Explorer and Safari

String.fromCharCode()
永远支持,加倍加速

String.fromCharCode() Supported since for ever, double as fast

区别:


尽管大多数常见的Unicode值可以用一个16位数字表示(正如JavaScript标准化早期所预期的那样),而fromCharCode()可用于返回单个字符表示最常见的值(即UCS-2值,它们是UTF-16的子集,具有最常见的特征rs),为了处理所有合法的Unicode值(最多21位),仅来自theCharCode()是不够的。由于较高的代码点字符使用两个(较低值)代理数字来形成单个字符,因此String.fromCodePoint()(ES6草案的一部分)可用于返回这样的一对,从而充分代表这些较高价值的字符。

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.


这篇关于你可以像String.fromCharCode一样使用String.fromCodePoint吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆