ES5 agrees to use reserved words directly as property names. But do not agree to use reserved words directly as function names
Set the existing class Nsmap to add the Delete method to the Nsmap prototype, such as
function Nsmap () {}nsmap.prototype.delete=function Delete () {};
The browser resolves the error
syntaxerror:unexpected token Delete
So why is native code map able to do that?
It was later thought that the identifier could consist of most of the Unicode characters except the ASCII special characters, and the scheme came:
1. Choose a character from the reserved word, such as the character T, to figure out the hexadecimal charcode of the character T.
"T". charCodeAt (0). toString (16)//"74"
2. Try to represent T with \x74. Use dele\x74e as the function name, no
Nsmap.prototype.delete=function dele\x74e () {};
3. Try to express T with \u0074, using dele\u0074e as the function name, and finally no error
Nsmap.prototype.delete=function dele\u0074e () {};
(A little puzzled here.) \x74 and \u0074 not the same, it's possible that the parser's performance considerations do not support \x)
4. Assuming that the function is declared independently, the reference function must not directly use literal reserved words
function dele\u0074e () {}nsmap.prototype.delete=dele\u0074e;
When used more, be able to write in the same way as Chrome's underlying JavaScript source code
Installfunctions (nsmap.prototype,dont_enum,["extends", function Ex\u0074ends () {}, "delete", function dele\u0074e () { }]);
Attach the previous escape function
function tocharcodestring () {return Array.prototype.map.call (new String (This), function (c) {var code=c.charcodeat (0), Hex=code.tostring (+);//return code>0xff?"\\u" + "substr" (0,4-hex.length) +hex://"\\x" + "0". substr (0,2-hex.length) +hex;return "\\u" + "$". substr (0,4- hex.length) +hex;}). Join ("");} Tocharcodestring.call ("delete"); "\u0064\u0065\u006c\u0065\u0074\u0065" Tocharcodestring.call ("Unicode character"); "\u0055\u006e\u0069\u0063\u006f\u0064\u0065\u5b57\u7b26"
JavaScript (ES5) uses reserved words for function names