String.fromCodePoint(num1[, ...[, numN]])
方法String.fromCharCode(65) // A String.fromCharCode(90) // Z String.fromCharCode(97) // a String.fromCharCode(122) // z
String.fromCharCode(num1[, ...[, numN]])
方法String.fromCodePoint(65) // A String.fromCodePoint(90) // Z String.fromCodePoint(97) // a String.fromCodePoint(122) // z
fromCodePoint()
, fromCharCode()
兩個都是String
的靜態方法,因此直接使用,不須要實例化。
二者的主要區別是:
fromCharCode()
出現的早,能夠處理經常使用的字符編碼
fromCodePoint()
ES2015出現的,能夠處理高位編碼。code
'A'.charCodeAt() // 65 'a'.charCodeAt() // 97 'Z'.charCodeAt() // 90 'z'.charCodeAt() // 122
參考:ip