unicorn/prefer-code-point 迂腐
用途
更希望使用 String.prototype.codePointAt 而不是 String.prototype.charCodeAt。更希望使用 String.fromCodePoint 而不是 String.fromCharCode。
为什么不好?
Unicode 在 String#codePointAt() 和 String.fromCodePoint() 中得到了更好的支持。
String.fromCodePoint() 和 String.fromCharCode() 之间的区别
示例
对此规则来说,错误代码示例
javascript
"🦄".charCodeAt(0);
String.fromCharCode(0x1f984);对此规则来说,正确代码示例
javascript
"🦄".codePointAt(0);
String.fromCodePoint(0x1f984);